Question

II. Answer part A, B, and C. Remember that 0 is not a positive value! 2a)...

II. Answer part A, B, and C. Remember that 0 is not a positive value!

2a)

Return true if at least one parameter value is positive, and false otherwise.


atLeastOnePositive(1, 0, 3) → true
atLeastOnePositive(-10, 0, -4) → false
atLeastOnePositive(3, -2, -4) → true

2b)

Return true if exactly one parameter value is positive, and false otherwise.

exactlyOnePositive(1, 0, 3) → false
exactlyOnePositive(-10, 0, -4) → false
exactlyOnePositive(3, -2, -4) → true

2c)

Return the middle of three integer values. This is the value such that it is less than or equal one value, and greater than or equal the other.

midOfThree(1, 2, 3) → 2
midOfThree(200, 100, 300) → 200
midOfThree(33, 11, 22) → 22

Homework Answers

Answer #1

// 2a)
public static boolean atLeastOnePositive(int n1, int n2, int n3) {
    return n1 > 0 || n2 > 0 || n3 > 0;
}

// 2b)
public static boolean exactlyOnePositive(int n1, int n2, int n3) {
    int count = 0;
    if (n1 > 0) ++count;
    if (n2 > 0) ++count;
    if (n3 > 0) ++count;
    return count == 1;
}

// 2c)
public static int midOfThree(int n1, int n2, int n3) {
    int min = n1, max = n1;
    if (n2 > max) max = n2;
    if (n3 > max) max = n3;
    if (n2 < min) min = n2;
    if (n3 < min) min = n3;
    return (n1 + n2 + n3) - (min + max);
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In C++ 1) Write the function definition that has 1 pass by value integer parameter. The...
In C++ 1) Write the function definition that has 1 pass by value integer parameter. The function contains logic to return true if the parameter is even and false if it is not. 2 ) Write a main function that prompts the user for a value, calls the function that you created in step one with the value entered by the user, display "even" if the function return true and otherwise displays "odd"
You need to answer each of the following questions. You need to show your work. Your...
You need to answer each of the following questions. You need to show your work. Your answer should be submitted in an attachment that is in Microsoft or PDF format. 1. Suppose a zero coupon security has a face value of $1000 and a maturity of 5 years. If the return on comparable securities is 6%, calculate the market price of this security. 2. Suppose a coupon security has a face value of $1000, a maturity of 4 years, a...
C++ only: Please implement a function that accepts a string parameter as well as two character...
C++ only: Please implement a function that accepts a string parameter as well as two character arguments and a boolean parameter. Your function should return the number of times it finds the character arguments inside the string parameter. When both of the passed character arguments are found in the string parameter, set the boolean argument to true. Otherwise, set that boolean argument to false. Return -1 if the string argument is the empty string. The declaration for this function will...
Find the value of C > 0 such that the function ?C sin2x, if0≤x≤π, f(x) =...
Find the value of C > 0 such that the function ?C sin2x, if0≤x≤π, f(x) = 0, otherwise is a probability density function. Hint: Remember that sin2 x = 12 (1 − cos 2x). 2. Suppose that a continuous random variable X has probability density function given by the above f(x), where C > 0 is the value you computed in the previous exercise. Compute E(X). Hint: Use integration by parts! 3. Compute E(cos(X)). Hint: Use integration by substitution!
True or false. If your answer is false, you must justify your answer with a one...
True or false. If your answer is false, you must justify your answer with a one sentence explanation to receive any credit. An asset depreciated in the 3-years MACRS class will have book value of 0 at the end of 3 years. The discounted payback period will always be no shorter than the undiscounted payback period. If the internal rate of return on an investment is positive, then the investment’s net present value must be positive. You are purchasing a...
Given the following prediction Sample ID Predicted Value Ground Truth 1 0.9 1 2 0.3 1...
Given the following prediction Sample ID Predicted Value Ground Truth 1 0.9 1 2 0.3 1 3 0.7 1 4 0.8 -1 5 0.4 -1 6 0.2 -1 (a) (18 Pts) Using 0.5 as the cutoff value, namely, the sample is predicted as 1 if predicted value >=0.5, otherwise -1. Please compute true positive rate (tpr, also called recall/sensitivity), false positive rate (fpr), true negative rate (tnr), false negative rate (fnr), accuracy and precision, respectively.
(In Python) Complete the isPrime() function to take an int and return True if it is...
(In Python) Complete the isPrime() function to take an int and return True if it is a prime number and False if it is not. Note: A prime number is not evenly divisible (meaning, the remainder is not 0) for all numbers smaller than itself (down to 2). For example, if num is 7, then you could test: if 7 remainder 6 is not 0, then if 7 remainder 5 is not 0, then if 7 remainder 4 is not...
2. You are facing two investment opportunities. The first one will return you with an uneven...
2. You are facing two investment opportunities. The first one will return you with an uneven stream of cash flows. The second one is annuity payments. Assume a 4.9% discount rate (your opportunity cost for money) and payments are in the end-of-period. (2a) How much you are willing to pay for this uneven stream of cash flows? Round to the nearest whole dollar. Year Cash Flow 1 $3,300 2 $3,300 3 $4,500 4 $5,300 (2b) If the investment will provide...
1) ____________ are examples of financial intermediaries. Select one: a. Commercial banks b. Insurance companies c....
1) ____________ are examples of financial intermediaries. Select one: a. Commercial banks b. Insurance companies c. Investment companies d. All of the above 2) True or False? In an efficient market, information is free. Select one: True False 3) If interest rates increase 3 percent and the average duration of a bank’s $100 million of assets is 4 years, the value of those assets will fall: Select one: a. $3.000.000 b. $4.000.000 c. $1.000.000 d. $12.000.000 4) True or False?...
QUESTION 1 Under the CAPM, investors require a rate of return that is proportional to the...
QUESTION 1 Under the CAPM, investors require a rate of return that is proportional to the volatility of each asset.   True False QUESTION 2 The simple average of all equity betas in a market must equal exactly 1, by construction. True False QUESTION 3 All assets and portfolios that plot on the Capital Market Line have returns that are perfectly positively correlated with the market portfolio. True False QUESTION 4 A firm that operates in rural areas, and is more...