In: Computer Science
Java
Create a class named Billing that includes three overloaded computeBill() methods for a photo book store.
main()
main() will ask the user for input and then call functions to do calculations. The calculations will be returned to main() where they will be printed out.
First function
Create a function named computeBill that receives on parameter. It receives the price of an item. It will then add 8.25% sales tax to this and return the total due back to main().
Second function
Create another function named computeBill that receives 2 parameters. It will receive the price of an item and the quantity ordered. It will calculated the total and then add 8.25% sales tax to that and return total due back to main().
Third function
Create a third function names computeBill that receives 3 parameters. It will receive the price of an item, the quantity ordered, and a coupon value. It will then calculate the total, then deduct the coupon amount, and add 8.25% sales tax. It will then return the total due to main().
Prompts and output
The prompts the user are easy to understand. Output is formatted to look like currency
import java.util.Scanner;
public class Billing
{
public double computeBill(double price)
{
return (price+price*0.0825);
}
public double computeBill(double price,int quantity)
{
return (price*quantity+price*quantity*0.0825);
}
public double computeBill(double price,int quantity,double
coupon)
{
double total=price*quantity-coupon;
return (total+total*0.0825);
}
public static void main(String[] args)
{
Billing b = new Billing();
Scanner sc = new Scanner(System.in);
System.out.print("Enter the price:
");
double price1=sc.nextDouble();
System.out.println("Bill = $"+b.computeBill(price1));
System.out.print("Enter the price:
");
double price2=sc.nextDouble();
System.out.print("Enter the
quantity: ");
int quantity=sc.nextInt();
System.out.println("Bill =
$"+b.computeBill(price2,quantity));
System.out.print("Enter the
price: ");
double price3=sc.nextDouble();
System.out.print("Enter the
quantity: ");
int quantity2=sc.nextInt();
System.out.print("Enter the coupon
value: ");
double coupon=sc.nextDouble();
System.out.println("Bill =
$"+b.computeBill(price3,quantity2,coupon));
}
}