JAVA Modifications file

profileCHEGG_

First Modifications to CWM billing.java file

 

At the end of the LM6 CWM video, you have a billing.java file that contains two computeBill methods.  One is for one photo book, the other is for multiple photo books.  Modify you programs so that does the following:

 

Open up your billing.java file and save as LM6Assignment.  After that, change your class name to LM6Assignment.

In main, create a variable called numBooks of type Int and write a statement that will ask the user to enter how many photo books they want to purchase.  Remember to include import java.util.Scanner; above your class and Scanner inputDevice = new Scanner(System.in);  in main.

In your call to computeBill that takes 2 arguments, instead of the number 4, pass it the variable numBooks such as multBooks = computeBill(onePhotoBook, numBooks);

At this point, compile and run your code.  The sample output might look something like the following:

The cost of one photo book is $11.87

 

How many Photo Books would you like to purchase: 7

 

The cost of multiple photo books is $83.08

 

Second Modifications to LM6Assignment.java file

 

 

Our next task will be to write a 3rd computeBill method that receives three parameters.  They represent the price of a photo book, the quantity ordered as entered from the user, and a coupon value.  Multiply the coupon quantity and price, reduce the result by the coupon value, and then add the 8% tax and return the total due.  Start by doing the following:

 

·                     Create a third overloaded method that also takes in coupon value such as    public static double computeBill(double amt, int quantity, double couponvalue)

 

·                     In main, create a variable called couponValue and ask the user to enter the percent of a discount in decimal format.  For example, a 15% discount would be entered as .15.  Also in main, create a double variable called multBooksWithCoupon.

 

·                     In main, make a new/third call to computeBill that takes three arguments and returns totalDue, such as:       multBooksWithCoupon = computeBill(onePhotoBook, numBooks, couponValue);

 

·                     In main, display the cost of multiple books with a coupon code.  This will not work until you write the third overloaded method.

 

Third Modification to LM6 Assignment.java file

 

We already wrote the method header for the third overloaded method that takes 3 arguments.  Now, we need to code the details.  So far, our third method should look like this:

 

   public static double computeBill(double amt, int quantity, double couponValue)   {      }

 

In the body of the method between the {  } we need to multiply the quantity and price, and then reduce the result by the coupon value, and then add the 8% tax and finally return totalDue.  The breakdown of variables declared and formulas are:

 

double totalDue = 0; //local variable     

double subTotal = 0; //local var     

double tax = 0; //local var     

double discount = 0;     

subTotal = amt * quantity;     

discount = subTotal * couponValue;     

tax = (subTotal - discount) * .08;     

totalDue = subTotal - discount + tax;      

Sample output of the program working properly:

 

Run 1:

 

The cost of one photo book is $11.87

 

How many Photo Books would you like to purchase: 12

 

What is the value of the coupon? Ex: for 15% enter .15 or for 20% enter .2:  .15

 

The cost of multiple photo books is $142.43

 

The cost of multiple photo books with a coupon is $121.07

 

Run 2:

 

The cost of one photo book is $11.87

 

How many Photo Books would you like to purchase: 7

 

What is the value of the coupon? Ex: for 15% enter .15 or for 20% enter .2:  .15

 

The cost of multiple photo books is $83.08

 

The cost of multiple photo books with a coupon is $70.62

 

What to attach?

 

Be sure to include your sample output at the bottom of your code in comments.  Attach your .java file when your program is complete, compiles, and is executable.

 

see attached for the billing syntex that MUST be used.

  • 9 years ago
  • 10
Answer(0)
Bids(1)