1. Your program asks the user how many bananas they want to buy, and what the price...
Question:
1. Your program asks the user how many bananas they want to buy, and what the price is.
This information is then passed to getTotal to calculate the total cost.
System.out.println("How many bananas ya want?");
quantity = reader.nextInt();
System.out.println("What's the price per banana?");
pricePerBanana = reader.nextDouble();
System.out.println("Total: $" + getTotal(quantity, pricePerBanana));
Your program has both of these methods:
public static double getTotal(double num, double price) {
return (num * price);
}
public static double getTotal(int num, int price) {
return (num * price);
}
Which of these methods will your program use?
A. getTotal(double num, double price)
B. getTotal(int num, int price)
C. Neither will work because you're trying to pass an int (quantity) and then a double (pricePerBanana).
2. int x = 7;
is the same as
Integer x = 7;
A. False. If you want to store an integer value it should be like this: int x = 7
B. True. They both have the integer value 7.
C. False. While they both hold the integer value of 7, only one of them can be stored in an array.
D. False. One is an object.
E. False. Only one of those can be used with methods.
3. Banana b1 = new Banana("Cavendish", 1.99, true);
Banana b2 = new Banana("Apple", 1.39, true);
Banana b3 = new Banana("Latundan", 2.49, false);
Banana[] bananas = {b1, b2, b3};
A. The code above is valid.
B. The code above is not valid because there is a typo. :)
C. The code above is not valid because you cannot put objects (like those referenced by the variables b1, b2, b3) into an array.
D. The code above is not valid because "Banana[]" is not valid code lol. Ya can't make a Banana array!
E. The code above is not valid because the constructor arguments aren't valid.