You created a class named Purchase. Each Purchase contains an invoice number, amount of sale, amount of
Question:
You created a class named Purchase. Each Purchase contains an invoice number, amount of sale, amount of sales tax, and several methods. Add get methods for the invoice number and sale amount fields so their values can be used in comparisons. Next, write a program that declares an array of five Purchase objects and prompt a user for their values. Then, in a loop that continues until a user inputs a sentinel value, ask the user whether the Purchase objects should be sorted and displayed in invoice number order or sale amount order. Save the file as SortPurchasesArray.java.
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 33% (12 reviews)
import javautilScanner public class SortPurchasesArray public static void mainString args Purchase purchases new Purchase6 int i String message char choice final char QUIT Z int number double price Scanner keyboard new ScannerSystemin fori 0 i purchaseslength i SystemoutprintEnter invoice number number keyboardnextInt SystemoutprintEnter sale amount price keyboardnextDouble purchasesi new Purchase purchasesisetInvoiceNumbernumber purchasesisetSaleAmountprice keyboardnextLine Systemoutprint Sort Purchases by Invoice number or Sale amount choice keyboardnextLinecharAt0 whilechoice QUIT ifchoice I sortByInvoicepurchases message Sorted by invoice number displaypurchases message else ifchoice S sortBySaleAmountpurchases message Sorted by sale amount displaypurchases message else SystemoutprintlnInvalid choice Systemoutprintln Sort Purchases by Invoice number or Sale amount Systemoutprint or enter QUIT to quit choice keyboardnextLinecharAt0 public static void sortBySaleAmountPurchase array int a b Purchase temp int highSub arraylength 1 for a 0 a highSub a for b 0 b highSub b ifarraybgetSaleAmount arrayb 1getSaleAmount temp arrayb arrayb arrayb 1 arrayb 1 temp public static void sortByInvoicePurchase array int a b Purchase temp int highSub arraylength 1 for a 0 a highSub a for b 0 b highSub b if arraybgetInvoiceNumber arrayb 1getInvoiceNumber temp arrayb arrayb arrayb 1 arrayb 1 temp public static void displayPurchase p ...View the full answer
Answered By
Utsab mitra
I have the expertise to deliver these subjects to college and higher-level students. The services would involve only solving assignments, homework help, and others.
I have experience in delivering these subjects for the last 6 years on a freelancing basis in different companies around the globe. I am CMA certified and CGMA UK. I have professional experience of 18 years in the industry involved in the manufacturing company and IT implementation experience of over 12 years.
I have delivered this help to students effortlessly, which is essential to give the students a good grade in their studies.
3.50+
2+ Reviews
10+ Question Solved
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
You know that how probability values can be used in managerial decision-making to establish a product guarantee, post a comment where you think probability could be used to help solve other...
-
A small immersion heater can be used in a car to heat a cup of water for coffee or tea. If the heater can heat 120mL of water from 25oC to 95oC in 8.0min, (a) Approximately how much current does it...
-
Write a program that declares a named constant to hold the number of quarts in a gallon (4). Also declare a variable to represent the number of quarts needed for a painting job, and assign an...
-
Create a 3-panel informational brochure on threats to government computer systems and the potentials effects of these threats. To create your brochure, you can use brochure builder or another program...
-
Eva and Mario are married on June 14, 2015. They use Eva's home as their principal residence. Eva purchased the home for $97,000 in 2012. On January 13, 2016, Eva and Mario are divorced. As part of...
-
Tully Corporation's Kearney Plant in Jacksonville, Florida, produces the company's weed control chemical solution, Weed Terminator. Production begins with pure water from a controlled stream to which...
-
Why does the natural frequency of a beam become lower if the effects of shear deformation and rotary inertia are considered?
-
Return to Problem 11 and the workforce schedule for part-rime loading dock workers. Suppose that each part- time worker can work only 3 days but the days must be consecutive. Devise an approach to...
-
Recap, a calendar year taxpayer, owns a piece of equipment that Recap uses in business. The equipment was purchased in year one for $100,000, and is "5-year property" within the meaning of 168(c). In...
-
The average daily cost of living in dollars (x) and the average wage in dollars (y) in 12 regions of a country are shown in the following table. x 77 84 88 77 89 105 69 85 78 91 78 110 y 134 149 136...
-
An advantage to using an enumerated data type is ____________. a. Errors are reduced because only a limited set of values can be used with the type b. Time is saved because programs with enumerated...
-
Create an application that contains an enumeration that represents the days of the week. Display a list of the days, and then prompt the user for a day. Display business hours for the chosen day....
-
1. Rich Snyder was twenty-four years old when he assumed leadership of In-N-Out after his father passed away. Do you think his young age was an asset or a liability for his leadership? Or did it...
-
how moral hazard can occur in the context of welfare programs and the three things that can be done to reduce moral hazard in welfare programs (please explain each of the three in general and mention...
-
There are many variables that are important in economic theory but are unobserved. Give an example of an unobserved economic variable which is important for policy decisions.
-
Discuss critically how the government uses suitable policies to stimulate the Malaysian economy by developing new and existing economic clusters and economic policies.
-
How does an increase in labour productivity affect the cost of producting goods and services? Explain. In 1975 your grand parent experienced a real increase in standard of living of 8%. Inflation was...
-
If a project requires an initial investment of $25,000 and is then sold for $42,000 after 5 years, what is its NPV at an interest rate of 6%? What is its IRR?
-
Discuss the psychological aspects associated with how Groupons board and executives analyzed whether or not they should accept Googles offer. Consider the notion of transaction utility. How does this...
-
1) The government decided to reduce taxes on fast-food to increase revenue. The government assumes that fast-food products have a) An inelastic demand b) An elastic demand c) A demand curve that is...
-
The Path class getFileName() method returns . a. The String representation of a Path b. An absolute Path c. The first item in a Paths list of name elements d. The last item in a Paths list of name...
-
A file channel . a. Can be read from b. Can be written to c. Is seekable d. All of the above are true.
-
If you add fewer than five components to a BorderLayout, _______________. a. Any empty component regions disappear b. The remaining components expand to fill the available space c. Both a and b d....
-
A hedge fund has a $20 million portfolio with a beta of 2. The fund manager is concerned about the stock market over the next 3 months. He plans to use 4-month S&P 500 index futures to hedge his...
-
Discuss the integration of Building Information Modeling (BIM) and Virtual Reality (VR) technologies in the planning, design, and construction phases of infrastructure projects, emphasizing their...
-
Liquid water at 80C and at 1atm flows through a heated pipe at a flow rate of 3.1 kg/s. It then leaves the pipe as steam. The water receives 9753840 J of heating from the pipe. Calculate the...
Study smarter with the SolutionInn App