Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help complete assignment in Java(leave a comment for additional information) Thanks Java code: From Milestone 1 Product.java public class Product { //fields of the
Please help complete assignment in Java(leave a comment for additional information) Thanks
Java code: From Milestone 1
Product.java
public class Product { //fields of the class private String name ; private int id ; private double price ; // parametrized constructor to set the data public Product(String name, int id, double price) { super(); this.name = name; this.id = id; this.price = price; } // getters to retrieve the data public String getName() { return name; } public int getId() { return id; } public double getPrice() { return price; } } Inventory.java
public class Inventory { // for each product we will use a parallel array to store the quantity ArrayListquantity = new ArrayList (); ArrayList products = new ArrayList (); Scanner sc = new Scanner(System.in); Inventory() { // initialize the inventory } void addProduct(Product obj) { // method to add a new product to the inventory products.add(obj); quantity.add(0); } int getStocks(int id) { // given a product id, return the stock of that product int index; for (Product i : products) { if (i.getId() == id) { // then find the index of that id index = products.indexOf(i); return (quantity.get(index));// return the quantity of that product } } return 0; // invalid stock } void addStock(int id, int addedStockValue) { // add the specified amount of stock to given id. if id is not found create a new id add the stock to it int index; for (Product i : products) { if (i.getId() == id) { // then find the index of that id index = products.indexOf(i); int value = quantity.get(index); //get the current value of the stock // add the new stock to that product quantity.set(index, value + addedStockValue); return; } } // if the loop ends , then the product is not there, so create anew System.out.print(" Enter the name of the product : "); String name = sc.next(); System.out.print(" Enter the price of the product : "); float price = sc.nextFloat(); // create the new product products.add(new Product(name, id, price)); // add the stock to the arraylist quantity.add(addedStockValue); } void removeStock(int id, int stockToRemove) { // find the exact product int index; for (Product i : products) { if (i.getId() == id) { // then find the index of that id index = products.indexOf(i); int value = quantity.get(index); //get the current value of the stock // update the new stock to that product value = value - stockToRemove; if (value StoreManager.java
public class StoreManager { public static void main(String[] args) { // create the inventory object Inventory obj = new Inventory(); } }Main.java
public class Main { public static void main(String[] args) { // write your code here } }Updates to the Store Manager Class The Store Manager needs some new functionality. Now, it will not only be managing the Inventory, but it will also be managing user Shopping Carts. Each user that connects to the store (new StoreView instance) should have their own unique Shopping Cart. If a user adds something to their cart, the Product's stock in the store Inventory should be decreased accordingly. A user can also remove items from their cart. Note that if the user removes a product from the shopping cart, the inventory must also be updated accordingly. Upon request, the Store Manager should return a new, unique cartID. This means Store Manager should be keeping track of cartIDs in some way. It could be as simple as having a counter that increments every time a new Shopping Cart is made. This implementation is ultimately up to you. Just be sure to document what you do! A user needs to be able to checkout once they are ready (your method for processing a transaction from Milestone 1 will likely need to be changed, or completely removed...). This method should return the total and summary of the items in the cart (print it for the user to see). You can choose to disconnect the user at this point or reset the ort- up to you! If the user quits before checking out, any items in the cart should be returned to the Inventory stock. Note: quitting means the user entered 'quit', not your program suddenly closes; you do not need to worry about that. Now that you will be implementing the UI for the store, you need some way to get the information needed to drive this Ul. Store Manager should have some methods that return needed information about Shopping Carts, or available Products. The Store View class will be using this information to populate the UI for the user. Remember, all communication by the Store View class must be done with the Store Manager only! Questions 1. What kind of relationship is the StoreView and Store Manager relationship? Explain. 2. Due to their behavioral similarity, would make sense to have Shopping Cart extend Inventory, or the other way around? Why or why not? 3. What are some reasons you can think of for why composition might be preferable over inheritance? These do not have to be Java-specific. 4. What are some reasons you can think of for why inheritance might be preferable over composition? These do not have to be Java-specific. Milestone 2 Deliverables 1. The following classes completed according to Milestone 2 specifications: StoreView.java, Shopping Cart.java, Inventory.java, Store Manager.java, and. Do not jump ahead! APPENDIX public static void main(String[] args) { StoreManager sm = new StoreManager(); StoreView svl = new StoreView(sm, sm.assignNewCartID()); StoreView sv2 = new Storeview (sm, sm.assignNewCartID()); StoreView sy3 = new StoreView(sm, sm.assignNewCartID()); StoreView [] users = {svl, sv2, sv3); int activeSV = users.length; Scanner sc = new Scanner (System.in); while (activeSV > 0) { System.out.print("CHOOSE YOUR STOREVIEW >>> "); int choice = sc.nextInt(); if (choice = 0) { if (users (choice] != null) { String chooseAnother = ""; while (!chooseAnother.equals("/") && !chooseAnother.equals("Y")) { // this implementation of displayGUI waits for input and displays the page // corresponding to the user's input, it does this once, and then returns I true if the user entered 'checkout' or 'quit'. if (users (choice].displayGUI()) { users [choice] = null; activeSV--; break; } System.out.print ("GO TO ANOTHER STOREVIEW? (y) >>> "); chooseAnother = sc.next(); } } else { System.out.println("MAIN > ERROR > BAD CHOICE THAT STOREVIEW WAS DEACTIVATED"); } } else { System.out.println( String.format("MAIN > ERROR > BAD CHOICE PLEASE CHOOSE IN RANGE ($d, $d]", 0, users.length - 1) } System.out.println("ALL STOREVIEWS DEACTIVATED"); } MILESTONE 1 Overview In this milestone, you will develop the UML Class diagram of your software using the information provided in this overview. You will also be coding the beginnings of the Store Manager, Inventory and Product classes. You can find the specific requirements for each class below. Keep in mind that most of the tasks you will be required to do are relatively open-ended. You must justify in your Change Log any decisions you made that were not obvious. For example, you should give a brief reason why you used an Array instead of an ArrayList for a class field. However, you should not explain why you gave studentName a type of String. Another example: you do not need to explain why you made a class method public, or a class field private, because doing this is usually normal. But, if for some reason, you made a class attribute protected, you need to explain why. The Product Class The Product class will store information about items being sold by the store. A Product object must only have a (1) name, (2) id, and (3) price. It does not have any other fields. The information in these fields should be retrievable but cannot be changed once the Product object is created. The Inventory Class The Inventory class will track the state of the inventory of your system. It should keep track of the type and quantity of each Product, as well as provide methods to access and modify this information. The following functionalities should be available in any given Inventory object: Get the amount of stock for a given Product ID (Note: it is possible the Product does not exist in the Inventory!). Add a specified amount of stock for a given Product to the inventory (Note: new Products can be added!) Remove a specified amount of stock for a given Product ID from the inventory (Note: you cannot have negative stock, and you cannot delete Products from the Inventory; if a Product's stock reaches 0, leave it.). Get information on a Product given a Product ID. Initialize the Inventory; set the contents of the Inventory to some default values upon object creation. The Store Manager Class Store Manager is the "brain" of the system. It contains all the functionality for managing the Inventory, Shopping Carts, and providing information to the StoreView class. Store Manager manages a single Inventory and it will have a variety of methods - two for now- to interact with this Inventory object. Updates to the Store Manager Class The Store Manager needs some new functionality. Now, it will not only be managing the Inventory, but it will also be managing user Shopping Carts. Each user that connects to the store (new StoreView instance) should have their own unique Shopping Cart. If a user adds something to their cart, the Product's stock in the store Inventory should be decreased accordingly. A user can also remove items from their cart. Note that if the user removes a product from the shopping cart, the inventory must also be updated accordingly. Upon request, the Store Manager should return a new, unique cartID. This means Store Manager should be keeping track of cartIDs in some way. It could be as simple as having a counter that increments every time a new Shopping Cart is made. This implementation is ultimately up to you. Just be sure to document what you do! A user needs to be able to checkout once they are ready (your method for processing a transaction from Milestone 1 will likely need to be changed, or completely removed...). This method should return the total and summary of the items in the cart (print it for the user to see). You can choose to disconnect the user at this point or reset the ort- up to you! If the user quits before checking out, any items in the cart should be returned to the Inventory stock. Note: quitting means the user entered 'quit', not your program suddenly closes; you do not need to worry about that. Now that you will be implementing the UI for the store, you need some way to get the information needed to drive this Ul. Store Manager should have some methods that return needed information about Shopping Carts, or available Products. The Store View class will be using this information to populate the UI for the user. Remember, all communication by the Store View class must be done with the Store Manager only! Questions 1. What kind of relationship is the StoreView and Store Manager relationship? Explain. 2. Due to their behavioral similarity, would make sense to have Shopping Cart extend Inventory, or the other way around? Why or why not? 3. What are some reasons you can think of for why composition might be preferable over inheritance? These do not have to be Java-specific. 4. What are some reasons you can think of for why inheritance might be preferable over composition? These do not have to be Java-specific. Milestone 2 Deliverables 1. The following classes completed according to Milestone 2 specifications: StoreView.java, Shopping Cart.java, Inventory.java, Store Manager.java, and. Do not jump ahead! APPENDIX public static void main(String[] args) { StoreManager sm = new StoreManager(); StoreView svl = new StoreView(sm, sm.assignNewCartID()); StoreView sv2 = new Storeview (sm, sm.assignNewCartID()); StoreView sy3 = new StoreView(sm, sm.assignNewCartID()); StoreView [] users = {svl, sv2, sv3); int activeSV = users.length; Scanner sc = new Scanner (System.in); while (activeSV > 0) { System.out.print("CHOOSE YOUR STOREVIEW >>> "); int choice = sc.nextInt(); if (choice = 0) { if (users (choice] != null) { String chooseAnother = ""; while (!chooseAnother.equals("/") && !chooseAnother.equals("Y")) { // this implementation of displayGUI waits for input and displays the page // corresponding to the user's input, it does this once, and then returns I true if the user entered 'checkout' or 'quit'. if (users (choice].displayGUI()) { users [choice] = null; activeSV--; break; } System.out.print ("GO TO ANOTHER STOREVIEW? (y) >>> "); chooseAnother = sc.next(); } } else { System.out.println("MAIN > ERROR > BAD CHOICE THAT STOREVIEW WAS DEACTIVATED"); } } else { System.out.println( String.format("MAIN > ERROR > BAD CHOICE PLEASE CHOOSE IN RANGE ($d, $d]", 0, users.length - 1) } System.out.println("ALL STOREVIEWS DEACTIVATED"); } MILESTONE 1 Overview In this milestone, you will develop the UML Class diagram of your software using the information provided in this overview. You will also be coding the beginnings of the Store Manager, Inventory and Product classes. You can find the specific requirements for each class below. Keep in mind that most of the tasks you will be required to do are relatively open-ended. You must justify in your Change Log any decisions you made that were not obvious. For example, you should give a brief reason why you used an Array instead of an ArrayList for a class field. However, you should not explain why you gave studentName a type of String. Another example: you do not need to explain why you made a class method public, or a class field private, because doing this is usually normal. But, if for some reason, you made a class attribute protected, you need to explain why. The Product Class The Product class will store information about items being sold by the store. A Product object must only have a (1) name, (2) id, and (3) price. It does not have any other fields. The information in these fields should be retrievable but cannot be changed once the Product object is created. The Inventory Class The Inventory class will track the state of the inventory of your system. It should keep track of the type and quantity of each Product, as well as provide methods to access and modify this information. The following functionalities should be available in any given Inventory object: Get the amount of stock for a given Product ID (Note: it is possible the Product does not exist in the Inventory!). Add a specified amount of stock for a given Product to the inventory (Note: new Products can be added!) Remove a specified amount of stock for a given Product ID from the inventory (Note: you cannot have negative stock, and you cannot delete Products from the Inventory; if a Product's stock reaches 0, leave it.). Get information on a Product given a Product ID. Initialize the Inventory; set the contents of the Inventory to some default values upon object creation. The Store Manager Class Store Manager is the "brain" of the system. It contains all the functionality for managing the Inventory, Shopping Carts, and providing information to the StoreView class. Store Manager manages a single Inventory and it will have a variety of methods - two for now- to interact with this Inventory object
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started