Question 281
Product class, which applies a 25% bulk discount for orders of 10 or more.
public class Product
{
private String name;
private double price;
private int quantity;
public Product(String n, double p, int q)
{
name = n; price = p; quantity = q;
}
public double totalValue()
{
double base = price * quantity;
if (quantity >= 10)
base = base * 0.75;
return base;
}
}
What is returned by p.totalValue() for Product p = new Product("Pen", 7.0, 10);?Main Solution
Solution:
Correct: C. base = 7.0 × 10 = 70.0. Since quantity 10 ≥ 10, base = 70.0 × 0.75 = 52.5.
Answer: Correct: C
Answer images

