Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program named Invoice.java that asks the user for a unit price and quantity and then calculates and prints the total price after

 

image

Write a program named Invoice.java that asks the user for a unit price and quantity and then calculates and prints the total price after a discount based on the quantity. The discount is calculated as follows: Quantity Percent 0-25 2% 26-45 5.5% > 45 14% You must have the following methods in your program in addition to main: getDiscountPercent This method takes one parameter-the quantity ordered-and returns the percentage discount as described above. The value will be a percent, not a decimal; for example, 5.5% returns 5.5, not 0.055. This method must not print anything. displayResults This void method has two parameters: the unit price and the quantity ordered. It will do the calculation and printing of the results as follows: Call getDiscountPercent to find the discount percentage . Prints the discount percentage . Calculate and print, properly labeled: The total price before discount The amount of discount The price after the discount All monetary amounts must have exactly two digits to the right of the decimal point. All percentages must have exactly one digit to the right of the decimal point. The main method will prompt the user for the unit price and the quantity. If either one is less than zero, the program gives an error message. Otherwise, it will pass those values to display Results, which will do the rest of the work. Here is what the output might look like from running the program several times. Your output does not have to look exactly like this, but it must reflect the same information. Enter unit price: $35 Enter quantity: -2 Price and quantity must both be greater than or equal to zero. Enter unit price: $12.25 Enter quantity: 30 Your discount is 5.5%. Price before discount: $367.50 Amount of discount: Price after discount: ==== $20.21 $347.29 Enter unit price: $14.79 Enter quantity: 3 Your discount is 2.0%. Price before discount: $44.37 Amount of discount: $0.89 Price after discount: $43.48

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_2

Step: 3

blur-text-image_3

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

Matlab An Introduction with Applications

Authors: Amos Gilat

5th edition

1118629868, 978-1118801802, 1118801806, 978-1118629864

More Books

Students also viewed these Programming questions

Question

Am I just skimming over the problem?

Answered: 1 week ago