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
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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
1 The correct answer is A getTotaldouble num double price This is because in your program youre util...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started