Question: In java please With a combination of data and methods, objects now we have the ability to maintain far more information in a much more
In java please
With a combination of data and methods, objects now we have the ability to maintain far more information in a much more organized system. By creating arrays of objects, we can now really start to provide more complex collections of information in a programmer friendly system. Additionally, we can have our objects be a bit smarted in how they perform their actions to decrease the amount of work that needs to be implemented by the programmer. For this exercise, you will be creating an updated version of your ordering system from part 1 of this lab. First copy your code from OrderSystem.java into a new file SmartOrderSystem.java . Next copy your code from Product.java into a new file SmartProduct.java . Be sure to update your class names accordingly. In your SmartProduct class, make the following updates and additions: o Add a private integer variable to store the products ID number, and provide appropriate getter/setter methods o Add a constructor that takes in an integer to represent the products ID number, a String to store the products name, an integer to store the number of units of product the user wishes to order, and a double to store the price of a single unit of the product The constructor should use all of this information to set the appropriate variables in the object The constructor should also calculate the total price of the product and store that value in the appropriate variable o All other methods and variables should remain the same In your SmartOrderSystem class, make the following updates and additions: o Update your calcTotal method to return a double and take an array of SmartProduct objects as parameters. This method should now iterate through all of the products, sum up all of the total costs (which have already been calculated by the objects), and return the summed total. o In your main method: Comment out all of the previous code (You can remove this code once you are done with the updates, but some of the code can be reused when updating) Create a variable to store an array of SmartProduct objects Prompt the user for how many products they wish to order, and then allocate space for an array of that size Using a loop: Prompt the user for the name of the product they wish to order and the number of products they wish to order Create a new SmartProduct object with a unique product ID number, the name the user specified, the number of units the user specified, and a price of 9.99, and store the object in the array Output to the user, with an appropriate message and in a well-organized fashion, all of the information regarding products they ordered and the sum total for their order. Do not forget that all monetary values are output with a $ in front of the value and with exactly two decimal places of precision.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
