Java: Create a class named Billing that includes three overloaded computeBill()
ID: 3932762 • Letter: J
Question
Java:
Create a class named Billing that includes three overloaded computeBill() methods for a photo book store.
When computeBill() receives a single parameter, it represents the price of one photo book ordered. Add 8% tax, and return the total due.
When computeBill() receives two parameters, they represent the price of a photo book and the quantity ordered. Multiply the two values, add 8% tax, and return the total due.
When computeBill() receives three parameters, they represent the price of a photo book, the quantity ordered, and a coupon value. Multiply the quantity and price, reduce the result by the coupon value, and then add 8% tax and return the total due.
Write a main() method that tests all three overloaded methods.
Save the application as Billing.java.
Explanation / Answer
Here is the code for you:
import java.util.*;
class Billing
{
//When computeBill() receives a single parameter, it represents the price of one photo book ordered. Add 8% tax, and return the total due.
public static double computeBill(double price)
{
return price * 1.08;
}
//When computeBill() receives two parameters, they represent the price of a photo book and the quantity ordered.
//Multiply the two values, add 8% tax, and return the total due.
public static double computeBill(double price, int quantity)
{
return price * quantity * 1.08;
}
//When computeBill() receives three parameters, they represent the price of a photo book, the quantity ordered, and a coupon value.
//Multiply the quantity and price, reduce the result by the coupon value, and then add 8% tax and return the total due.
public static double computeBill(double price, int quantity, double couponValue)
{
return (price * quantity - couponValue) * 1.08;
}
public static void main(String[] args)
{
System.out.println("The price of book after taxes is: " + computeBill(10));
System.out.println("The price of 5 books after taxes is: " + computeBill(10, 5));
System.out.println("The price of 5 books after discount of 3$ and taxes is: " + computeBill(10, 5, 3));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.