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: 36% (11 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...
-
Calcium reacts with cold water to form calcium hydroxide, Ca(OH) 2 , and hydrogen, H 2 . a. State the oxidation number of calcium in: i. Calcium metal ii. Calcium hydroxide. b. State the oxidation...
-
You and your roommate are moving to a city \(320 \mathrm{mi}\) away. Your roommate drives a rental truck at a constant \(60 \mathrm{mi} / \mathrm{h}\), and you drive your car at \(70 \mathrm{mi} /...
-
Outdoor Recreation Products Inc. had 50,000 shares of common stock outstanding at the end of 2010. During 2011 and 2012, the following transactions took place. 2011 Mar. 31 Sold 10,000 shares at $24....
-
How do you gauge the efficacy of strategic planning interventions in fostering organizational resilience and adaptability amidst dynamic market conditions and technological advancements ?
-
Parker Company acquires an 80% interest in Sargent Company for $300,000 on January 1, 2015, when Sargent Company has the following balance sheet: The excess of the price paid over book value is...
-
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....
-
Make the same assumptions as in Problem 10. Martin's friend, Billy, wants to bet on the Yankees. He offers Martin the following wager: if the Yankees win, Martin will pay Billy $300; if the Giants...
-
Has looking beyond U.S. borders been a profitable experience for U.S. corporations?
-
Which number in a companys income statement should be used to measure its profitability relative to its total assets? Why?
-
What are earnings per share and dividends per share?
-
A low total asset turnover indicates that a firms total assets are not being managed efficiently. What additional information would you want to know when this is the case?
-
What is an amortized loan?
-
Under the common law, from the 1500s until today, the law has allowed past property owners to place limitations on the uses of real property in the future through the use of covenants (promises) as...
-
Cobb Manufacturing Company uses a process cost system and average costing. The following production data is for the month of June 2011. Production Costs Work in process, beginning of the month:...
-
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....
-
Describe one way to overcome procrastination we learned from de Janasz, Dowd and Schneider ( 2 0 2 2 ) and how that way helped you to complete this assignment before the deadline.
-
Ralph has total income of $ 5 3 0 0 0 . He has business expenses of $ 1 8 0 0 0 , made a $ 5 0 0 0 RRSP contribution and incurred $ 4 0 0 0 in tuition expenses for his daughter, who did not work and...
-
AT Travel Limited acquired a two - story building for use as an office on June 3 0 , 2 0 2 2 , at $ 2 million. The building is expected to have a useful life of 2 0 years and a residual value of $ 1...
Study smarter with the SolutionInn App