Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have the following exercise that I am trying to figure out: -Write three overloaded computeBill methods for a photo book store: -When computeBill receives

I have the following exercise that I am trying to figure out:

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

My code is listed below. I have tried many variations and keep getting errors when I try to compile. I would love some help explaining why it is not compiling and where I've gone wrong.

public class Billing { final static double TAX = 0.08; public static void main(String[] args) { // write your main() method here to test computeBill with one, two and three parameters double price = 10.5; int quantity = 3; double coupon = 5.6; System.out.println("The price of one book without tax is $" + price); System.out.println("The price with a single parameter is " + computeBill(price)); System.out.println("The price with two parameters is $" + computeBill(price,quantity)); System.out.println("The price with three parameters is $" + computeBill(price, quantity,coupon)); }

// overload a (public!) computeBill method with one parameter here public static void computeBill(double price) { double bill; bill = price * TAX + price; return bill; } // overload a (public!) computeBill method with two parameters here public static void computeBill(double price,int quantity) { double taxPrice; double bill; taxPrice = price * quantity * TAX; bill = price * quantity + taxPrice; return bill; } // overload a (public!) computeBill method with three parameters here public static void computeBill(double price,int quantity,double coupon) { double taxPrice; double bill; taxPrice = price * quantity * TAX; bill = price * quantity + taxPrice - coupon; return bill; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

Bringing about the destruction of a dream is tragic.

Answered: 1 week ago

Question

We are of the conviction that writing is important.

Answered: 1 week ago