Write a program named Invoice.java that asks the user for a unit price and quantity and...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
Predictive text entry systems are familiar on touch screens and mobile phones. This question asks you to consider how the same principles might be used in a programming editor for creating Java code....
-
cck3 java help them all If a processor exhibited one branch delay slot how would you reorder (and possibly modify) the instructions in the following loop to gain a performance advantage? loop ldr...
-
Suppose that Canada produces two goods: lumber and fish. It has 18 million workers, each of whom can cut 10 feet of lumber or catch 20 fish each day. a. What is the maximum amount of lumber Canada...
-
In Exercise 3.19, Consumer Reports6 gave the prices and screen sizes for the top 10 LCD TVs in the 46-inch and higher categories. Does the price of an LCD TV depend on the size of the screen? a....
-
Of the various types of mortgages discussed on the following two websites, http://www.mortgagecalculator.org/helpful-advice/types-of-mortgages.php and...
-
Describe triggers. Discuss their advantages and disadvantages.
-
Hewitt and Patel are partners, sharing gains and losses equally. They decide to terminate their partnership. Prior to realization, their capital balances are $28,000 and $18,000, respectively. After...
-
A pickle producer currently purchases lids for its jars from a certain manufacturing company. The lids must have a diameter of approximately 3.5 inches, and because the lids must fit securely, the...
-
What is protectionism, and how can it affect the MNC?
-
Expropriation occurs when a host government confiscates the assets of a corporation doing business in that country. Can expropriation occur in other ways? Explain.
-
What are blocked funds? How might they arise?
-
Why is the timing option important in investment decisions?
-
In what ways are the investment and abandonment options similar?
-
On June 1, Merando Company borrows $141,750 from First Bank on a 6-month, $141,750, 8% note. Prepare the entry on June 1. Prepare the adjusting entry on June 30. Prepare the entry at maturity...
-
Write each fraction as a percent. 7 50
-
See the option quote on IBM from the CBOE Web site on the next page showing options expiring in March and April 2022. a. Which option contract had the most trades that day? b. Which option contract...
-
Two European call options with a strike price of \($50\) are written on two different stocks. Suppose that tomorrow, the low-volatility stock will have a price of \($50\) for certain. The...
-
It is February 21, 2022, and you have decided to purchase 10 June call contracts on eBays stock with an exercise price of \($57.50.\) Because you are buying, you must pay the ask price. How much...
Study smarter with the SolutionInn App