1. Implement the Sales Record class which contains: A private attribute...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. Implement the Sales Record class which contains: ● ● ● ● ● A private attribute named numltems, which is an integer. It represents the total number of items being sold in one transaction or one sale. A private attribute named records, which is an integer array. The array stores the details of the sale. A public constructor with one argument: numltems, which is an integer. The constructor should initialise the above two attributes, e.g. setting the private attribute numitems to the value of argument numltems and initialising the array records as an empty array of length numltems *2. For example, if the value of argument numitems is 5, the private attribute numitems will be initialised as 5, and records will be initialised as an array of 5 * 2 = 10 integers. A public method named enterSales. The method stores the user input sequentially in the array records. For example, if numltems equals 5, the method prompts the user to enter 10 integers or 5 pairs of "price" and "quantity". Note, you can assume "price" is always the first in the pair. "Quantity" is always the second in the pair. A public method called printSales. This method prints the records array with each sale in one line, price and quantity of a sale separated by a comma and space, ending with a new line. A public method called minPrice. This method returns the lowest price stored in the records array. A public method called maxQuantity; this method returns the highest quantity in the records array. 2. Write the main method. This method prompts the user to enter an integer, which indicates the number of items in one sale. The integer must be positive. You can use the Scanner class to get input from the user. You must validate the user input. If the entered number is less than or equal to zero, an error message (see Sample Output below) should be displayed and the user prompted to try again. This repeats until valid input has been entered. NOTE: You can assume all input are integers, i.e., scanner.nextInt () will not crash due to wrong data types. 3. After valid input is entered, createaSalesRecord typed object with the provided number of items and then call the EnterSales method, which prompts the user to enter the price and quantity of each sale, one number per line. You need to validate the entered numbers to make sure they are all non-negative integer (larger or equal than zero). In the case where the entered number of a sale, either price or quantity is invalid, an error message should be displayed. Your program will prompt the user to enter again, until a valid input is entered. Once all sale data are entered, the printSales method is called, followed by minPrice and maxSold. Lastly the program should display "Thanks for entering this sale record." before terminating. Sample Output Sample output #1; with invalid input for numltems: Please enter the number of items: 0 Invalid input! Please try again! -5 Invalid input! Please try again! 2 Please enter the details of each item: 10 3 15 2 10, 3 15, 2 The lowest price: 10 The highest quantity: 3 Thanks for entering this sales record. Sample output #2; with invalid input for records: Please enter the number of items: 3 Please enter the details of each item: 200 9 70 0 Invalid sales data! Please try again! 7 -100 Invalid sales data! Please try again! 100 3 ====== 200, 70, 7 9 ==== 100, 3 The lowest price: 70 The highest quantity: 9 Thanks for entering this sales record. 1. Implement the Sales Record class which contains: ● ● ● ● ● A private attribute named numltems, which is an integer. It represents the total number of items being sold in one transaction or one sale. A private attribute named records, which is an integer array. The array stores the details of the sale. A public constructor with one argument: numltems, which is an integer. The constructor should initialise the above two attributes, e.g. setting the private attribute numitems to the value of argument numltems and initialising the array records as an empty array of length numltems *2. For example, if the value of argument numitems is 5, the private attribute numitems will be initialised as 5, and records will be initialised as an array of 5 * 2 = 10 integers. A public method named enterSales. The method stores the user input sequentially in the array records. For example, if numltems equals 5, the method prompts the user to enter 10 integers or 5 pairs of "price" and "quantity". Note, you can assume "price" is always the first in the pair. "Quantity" is always the second in the pair. A public method called printSales. This method prints the records array with each sale in one line, price and quantity of a sale separated by a comma and space, ending with a new line. A public method called minPrice. This method returns the lowest price stored in the records array. A public method called maxQuantity; this method returns the highest quantity in the records array. 2. Write the main method. This method prompts the user to enter an integer, which indicates the number of items in one sale. The integer must be positive. You can use the Scanner class to get input from the user. You must validate the user input. If the entered number is less than or equal to zero, an error message (see Sample Output below) should be displayed and the user prompted to try again. This repeats until valid input has been entered. NOTE: You can assume all input are integers, i.e., scanner.nextInt () will not crash due to wrong data types. 3. After valid input is entered, createaSalesRecord typed object with the provided number of items and then call the EnterSales method, which prompts the user to enter the price and quantity of each sale, one number per line. You need to validate the entered numbers to make sure they are all non-negative integer (larger or equal than zero). In the case where the entered number of a sale, either price or quantity is invalid, an error message should be displayed. Your program will prompt the user to enter again, until a valid input is entered. Once all sale data are entered, the printSales method is called, followed by minPrice and maxSold. Lastly the program should display "Thanks for entering this sale record." before terminating. Sample Output Sample output #1; with invalid input for numltems: Please enter the number of items: 0 Invalid input! Please try again! -5 Invalid input! Please try again! 2 Please enter the details of each item: 10 3 15 2 10, 3 15, 2 The lowest price: 10 The highest quantity: 3 Thanks for entering this sales record. Sample output #2; with invalid input for records: Please enter the number of items: 3 Please enter the details of each item: 200 9 70 0 Invalid sales data! Please try again! 7 -100 Invalid sales data! Please try again! 100 3 ====== 200, 70, 7 9 ==== 100, 3 The lowest price: 70 The highest quantity: 9 Thanks for entering this sales record.
Expert Answer:
Answer rating: 100% (QA)
Heres a simple implementation in Java import javautilScanner class SalesRecord private int numItems ... View the full answer
Related Book For
International Marketing
ISBN: 978-1452226354
1st edition
Authors: Daniel W. Baack, Eric G. Harris, Donald Baack
Posted Date:
Students also viewed these programming questions
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Display the TERM_DESC, COURSE_NAME, BLDG_CODE and ROOM for every course evertaught by faculty member John Blanchard. Question 2 Display the S_LAST, S_FIRST, COURSE_NAME, TERM_DESC and GRADE values...
-
Basler Ltd. incurs these expenditures in purchasing a truck: invoice price $42,000; installation of a trailer hitch $1,000; one-year accident insurance policy $2,000; motor vehicle licence $150;...
-
Use the graph of y = ax + b at the top of the next column to solve each equation and inequality. Write the solution set to each inequality in set-builder or interval notation. (a) ax + b = 0 (b) ax +...
-
This case arose after Felix DeWeldon, a well-known sculptor and art collector, sold three paintings to Robert McKean in 1994. Felix DeWeldon declared bankruptcy in 1991. In 1992, DeWeldon, Ltd.,...
-
You are provided with the following information for Lahti Inc. for the month ended June 30, 2014. Lahti uses the periodic method for inventory. Instructions (a) Calculate (i) ending inventory , (ii)...
-
Discuss why people often resist new ideas such as the Relational Model in Business Logic ?
-
The following wave function represents a travelling wave: y(x, t) 7.8 = 8.7 (6.3x5.6t) What is the phase velocity? Your Answer: Answer units
-
Express in polar form the product of the given complex numbers. 5(cos 125+i sin 125). 4(cos 31+i sin 31) 20(cos 156+i sin 156) 20(cos 94 +i sin 94) 20(cos 120+i sin 120) 20(cos 90 +i sin 90)
-
Which of these shows a pair of functions that are BOTH undefined at an angle of = 3T ? 2 tan a and cota csc a and co't a Osin a and cos a O sec a and tan a
-
10. A company estimates that it will sell N(x) units of a product after spending $x thousand on advertising. N(x)=4x-0.25x +500 0x12 a) How much money should the company spend on advertising to reach...
-
1 pts Calculate the refining margin for crude oil X in $ per barrel. Type the margin into the blank to two decimal places. Do not type the $ sign. So if you calculate the answer to be 5.30, type 5.30...
-
12. 12 points Using the iterative method (forward or backward substitution) solve the following recurrence relations with the given initial conditions. Show the steps of your calculation. Note: you...
-
Eco World Development Pte Ltd is at the developer company that owned Eco Grandeur in Setia Alam Centre, Selangor. The developer shows interest in material logistics as it will positively affect to...
-
The Place-Plus real estate development firm in Problem 24 is dissatisfied with the economists estimate of the probabilities of future interest rate movement, so it is considering having a financial...
-
In what ways does culture affect purchasing behavior?
-
Describe the three most common message strategies.
-
What are the 5 Cs of marketing channel structure?
-
What is the amount of cost of goods sold under variable costing? a. $220,000. b. $161,000. c. $154,000. d. $230,000.
-
When comparing Kelleys absorption costing net operating income to its variable costing net operating income, which of the following will be true? a. Its absorption costing net operating income will...
-
Dexter Corporation produces and sells a single product, a wooden hand loom for weaving small items such as scarves. Selected cost and operating data relating to the product for two years are given...
Study smarter with the SolutionInn App