Question

Create a class named Billing that includes four overloaded computeBill() methods for a photo book store....

Create a class named Billing that includes four 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.5% 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.5% 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.5% tax and return the total due.
  • When computeBill () receives four parameters, they represent the price of a photo book, the quantity ordered, a coupon value, and a weekly discount. Multiply the quantity and price, reduce the result by the coupon value plus the weekly discount, and then add 8.5% tax and return the total due.

Write a main () method that tests all four overloaded methods. Save the application as Billing.java.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is your answer ...

Code ::

//Include the header files.

import java.util.Scanner;

//Create a class.

public class Billing

{

//Declare and initialize the variable.

private static final double tax_percent = 0.085;

  

//Define the main() function.

public static void main(String[] args)

{

//Declare the variable.

boolean status = true;

//Create an object of scanner class.

Scanner ab = new Scanner(System.in);

//Begin the while loop.

while(true)

{

//Declare the variables.

double cost, cupn_val, discount_rate;

int quantity;

  

//Display the statements.

System.out.println("Case1: With one parameter.");

System.out.println("Case2: With two parameter.");

System.out.println("Case3: With "

+ "three parameter.");

System.out.println("Case4: With "

+ "four parameter.");

System.out.println("Enter the choice : ");

  

//Prompt the user to enter the choice.

int ch = ab.nextInt();

  

//Begin the switch case.

switch(ch)

{

//First case for only one parameter.

case 1 :

//Prompt the user to

//enter the cost.

System.out.println("Enter the "

+ "cost of book.");

cost = ab.nextDouble();

  

//Begin the while loop.

while(cost < 0)

{

//Display the statement.

System.out.println("Cost cannot "

+ "be negative!!!");

//Prompt the user to enter the

//cost.

System.out.println("Re-Enter the "

+ "cost of book.");

cost = ab.nextDouble();

}//End of while loop.

  

//Call the function.

computeBill(cost);

  

//Break the vase.

break;

  

//Second case for two parameters.

case 2:

//Prompt the user to enter

//the cost.

System.out.println("Enter the "

+ "cost of book.");

cost = ab.nextDouble();

  

//Begin the while loop.

while(cost < 0)

{

  

//Display the statement.

System.out.println("Cost cannot"

+ " be negative!!!");

//Prompt the user to enter the

//cost.

System.out.println("Re-Enter the "

+ "cost of book.");

cost = ab.nextDouble();

}//End of while loop.

  

//Prompt the user to enter

//the quantity.

System.out.println("Enter the "

+ "quantity of book.");

quantity = ab.nextInt();

  

  

//Begin the while loop.

while(quantity < 0)

{

//Display the statement.

System.out.println("Quantity cannot"

+ " be negative!!!");

//Prompt the user to enter

//the quantity.

System.out.println("Re-Enter the"

+ " quantity of book.");

quantity = ab.nextInt();

}//End of while loop.

  

//Call the function.

computeBill(cost, quantity);

  

//Break the case.

break;

  

//Third case for three parameters.   

case 3:

//Prompt the user to enter the cost.

System.out.println("Enter the cost"

+ " of book.");

cost = ab.nextDouble();

  

//Begin the while loop.

while(cost < 0)

{

//Display the statement.

System.out.println("Cost cannot "

+ "be negative!!!");

//Prompt the user to enter

//the cost.

System.out.println("Re-Enter the "

+ "cost of book.");

cost = ab.nextDouble();

}//End of while loop.

  

//Prompt the user to enter the quantity.

System.out.println("Enter the "

+ "quantity of book.");

quantity = ab.nextInt();

  

//Begin the while loop.

while(quantity < 0)

{

//Display the statement.

System.out.println("Quantity cannot"

+ " be negative!!!");

//Prompt the user to enter

//the quantity.

System.out.println("Re-Enter the "

+ "quantity of book.");

quantity = ab.nextInt();

}//End of while loop.

  

//Prompt the user to enter the cupn_val.

System.out.println("Enter the coupon "

+ "value for book.");

cupn_val = ab.nextDouble();

  

//Begin the while loop.

while(cupn_val < 0)

{

//Display the statement.

System.out.println("Coupon cannot"

+ " be negative!!!");

//Prompt the user to enter the cupn_val.

System.out.println("Re-Enter the Coupon"

+ " value for book.");

cupn_val = ab.nextDouble();

}//End of while loop.

  

//Call the function.

computeBill(cost, quantity, cupn_val);

  

//Break the case.

break;

  

//Fouth case for four parameters.

case 4:

//Prompt the user to enter the cost.

System.out.println("Enter the cost"

+ " of book.");

cost = ab.nextDouble();

  

//Begin the while loop.

while(cost < 0)

{

//Display the statement.

System.out.println("Cost cannot "

+ "be negative!!!");

//Prompt the user to enter

//the cost.

System.out.println("Re-Enter the "

+ "cost of book.");

cost = ab.nextDouble();

}//End of while loop.

  

//Prompt the user to enter the quantity.

System.out.println("Enter the "

+ "quantity of book.");

quantity = ab.nextInt();

//Begin the while loop.

while(quantity < 0)

{

//Display the statement.   

System.out.println("Quantity cannot"

+ " be negative!!!");

  

//Prompt the user to enter

//the quantity.

System.out.println("Re-Enter the "

+ "quantity of book.");

quantity = ab.nextInt();

  

}//End of while loop.

//Prompt the user to enter the cupn_val.

System.out.println("Enter the coupon "

+ "value for book.");

cupn_val = ab.nextDouble();

//Begin the while loop.

while(cupn_val < 0)

{

//Display the statement.

System.out.println("Coupon cannot"

+ " be negative!!!");

  

//Prompt the user to enter the cupn_val.

System.out.println("Re-Enter the Coupon"

+ " value for book.");

cupn_val = ab.nextDouble();

  

}//End of while loop.

//Prompt the user to enter

//the discount_rate.

System.out.println("Enter the discount_rate "

+ "for book.");

discount_rate = ab.nextDouble();

//Begin the while loop.

while(discount_rate < 0)

{

//Display the statement.   

System.out.println("Discount_rate cannot"

+ " be negative!!!");

//Prompt the user to enter the cupn_val.

System.out.println("Re-Enter the discount_rate"

+ " for book.");

discount_rate = ab.nextDouble();

  

}//End of while loop.

  

//Call the function.

computeBill(cost, quantity, cupn_val, discount_rate);

  

//Break the case.

break;

  

//Default case.

default:System.out.println("Invalid choice entererd.");

}

  

//Display the statement.

System.out.println("Press Y to continue and N to stop!!!");

  

//Prompt the user to enter the choice.

String press = ab.next();

  

//Begin the condition.

if(press.equalsIgnoreCase("Y"))

{

//Update the status.

status = true;

  

}//End of if.

  

//Else part of above if.

else

{

//Update the status.

status = false;

  

//Break the program.

break;

  

}//End of else part.

}//End of switch case.

}//End of main() function.

  

//Define a function.

public static void computeBill(double book_price)

{

//Compute the overall bill of book.

double total_bill= (book_price *

tax_percent)

+ book_price;

  

//Display the statement.

System.out.println("---------------Case1:"

+ "With one parameter----------------");

  

//Display the final bill.

System.out.println("Final bill of "

+ "book is : " + total_bill);

  

}//End of the function.

  

//Define a function.

public static void computeBill(double book_price,

int quatity_ordered)

{

//Compute the overall bill of book.

double total_bill = (book_price *

quatity_ordered * tax_percent)

+ (book_price * quatity_ordered);

  

//Display the statement.

System.out.println("---------------Case2:"

+ "With two parameters----------------");

  

//Display the final bill.

System.out.println("Final bill of "

+ "book is : " + total_bill);

  

}//End of the function.

  

//Define a function.

public static void computeBill(double book_price,

int quatity_ordered, double cupn_val)

{

//Compute the overall bill of book.

double books_val = (cupn_val) -

(book_price * quatity_ordered);

double total_bill = (books_val*tax_percent)

+ books_val;

  

//Display the statement.

System.out.println("---------------Case3:"

+ "With three parameters----------------");

  

//Display the final bill.

System.out.println("Final bill of "

+ "book is : " + total_bill);

  

}//End of the function.

  

//Define a function.

public static void computeBill(double book_price,

int quatity_ordered, double cupn_val,

double discount_val)

{

//Compute the overall bill of book.

double books_val = ((cupn_val) - (book_price

* quatity_ordered)) + discount_val;

double total_bill = (books_val*tax_percent)

+ books_val;

//Display the statement.

System.out.println("---------------Case4:"

+ "With four parameters----------------");

//Display the final bill.

System.out.println("Total cost for your"

+ " order is : " + total_bill);

  

}//End of the function.

  

}//End of class Billing.

Output ::

Thanks ...

Add a comment
Know the answer?
Add Answer to:
Create a class named Billing that includes four overloaded computeBill() methods for a photo book store....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a class named Billing that includes three overloaded computeBill() methods for a photo book store....

    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...

  • Create a Python file (book.py) that has a class named Book. Book class has four attributes,...

    Create a Python file (book.py) that has a class named Book. Book class has four attributes, title (string), author(string), isbn(string), and year(int). Title - the name of the book. Author - the name of the persons who wrote the book. ISBN - is a unique 13 digit commercial book identifier. Year - the year the title was printed. Your class should have the following methods: (1) __init__(self, title, author, isbn, year): This method called when an object (book) is created...

  • Create a Python file (book.py) that has a class named Book. Book class has four attributes, title...

    Create a Python file (book.py) that has a class named Book. Book class has four attributes, title (string), author(string), isbn(string), and year(int). Title - the name of the book. Author - the name of the persons who wrote the book. ISBN - is a unique 13 digit commercial book identifier. Year - the year the title was printed. Your class should have the following methods: (1) __init__(self, title, author, isbn, year): This method called when an object (book) is created...

  • Exercise 02: Based on LINQ extension methods. [15 marks] Create an Invoice class which includes four...

    Exercise 02: Based on LINQ extension methods. [15 marks] Create an Invoice class which includes four properties - a PartNumber ( type int), a PartDescription ( type string), a Quantity of item being purchased (type int) and a Pricel type decimal). Use the following sample data for Invoice class objects: Quantity 7 Part Number 87 24 7 77 39 68 Part Description Electric Sander Power Saw Sledge Hammer Hammer Lawn Mower Screw Driver Jig saw 18 11 76 3 Price...

  • Language = Java Create a program to receive book prices until a sentinel value is entered....

    Language = Java Create a program to receive book prices until a sentinel value is entered. (Be sure to tell your user what the sentinel value is so they can type it to indicate they are finished with entering input.) After the sentinel value is entered, compute the total book order total and return the following to the user. As book prices are entered, you'll need to have some way to capture the number of books they ordered and the...

  • WRITING METHODS 1. Implement a method named surface that accepts 3 integer parameters named width, length,...

    WRITING METHODS 1. Implement a method named surface that accepts 3 integer parameters named width, length, and depth. It will return the total surface area (6 sides) of the rectangular box it represents. 2. Implement a method named rightTriangle that accepts 2 double arameters named sideA and hypotenuseB. The method will return the length of the third side. NOTE To test, you should put all of these methods into a ‘MyMethods’ class and then write an application that will instantiate...

  • Additional info is this will use a total of four classes Book, BookApp, TextBook, and TextBookApp....

    Additional info is this will use a total of four classes Book, BookApp, TextBook, and TextBookApp. Also uses Super in the TextBook Class section. Problem 1 (10 points) Вook The left side diagram is a UML diagram for Book class. - title: String The class has two attributes, title and price, and get/set methods for the two attributes. - price: double Вook) Book(String, double) getTitle(): String setTitle(String): void + getPrice() double setPrice(double): void toString() String + The first constructor doesn't...

  • #6 Write a SELECT statement that returns these columns: The count of the number of orders...

    #6 Write a SELECT statement that returns these columns: The count of the number of orders in the Orders table The sum of the tax_amount columns in the Orders table Write a SELECT statement that returns one row for each category that has products with these columns: The category_name column from the Categories table The count of the products in the Products table The list price of the most expensive product in the Products table Sort the result set so...

  • In a new file located in the same package as the class Main, create a public...

    In a new file located in the same package as the class Main, create a public Java class to represent a photograph that consists of a linear (not 2D) array of pixels. Each pixel is stored as an integer. The photograph class must have: (a) Two private fields to represent the information stored about the photograph. These are the array of integers and the date the photograph was taken (stored as a String). The values in the array must be...

  • // Client application class and service class Create a NetBeans project named StudentClient following the instructions...

    // Client application class and service class Create a NetBeans project named StudentClient following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. Add a class named Student to the StudentClient project following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. After you have created your NetBeans Project your application class StudentC lient should contain the following executable code: package studentclient; public class...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT