Question: Using Java, you have been hired as the manager of a toy store to keep track of the items you have in your store. You

Using Java, you have been hired as the manager of a toy store to keep track of the items you have in your store. You decide that you need a new Java object: ToyStoreItem, and that you might need to handle such information in another object ToyStoreInventory. You then proceed to implement methods that you will need to buy toys in your store, in the file ShoppingCart.java.

In the class ToyStoreItem you need to create 2 constructors in which the parameters are : name, price, code and the second constructor is name, brand, price, batteriesRequired, age and code. Next create methods that allow to set or modify the values of the attributes (1 setter, 1 getter and anything else). Lastly a method called public void print() that prints the content of all attributes.

In the class ToyStoreInventory, two arrays are created ToyStore Item, which holds up to 25 items and array quantity which also hold 25 items. Create a constructor that eceives a file name and populates the inventory array. Set the quantity for each toy to 15, in the beginning, in the quantity array. For the two arrays, same index should point to same item. For example, if inventory [2] have information about a LEGO, quantity[2] would show how many LEGO toys are available in the store at that time. Create a Getter for numToys

print the name and the code of all the ToyStoreItems available in the inventory NOTE: print only those with quantity greater than 0 */ }

//Adds a ToyStoreItem to the inventory and the quantity of that toy. public void addToy(ToyStoreItem toAdd, int quantity) { //TO DO //Note: if the ToyStoreItem already exists in the inventory, add to the quantity. }

//Subracts ToyStoreItems from the inventory public void deleteToy(ToyStoreItem toDelete, int quantity){ //TO DO //Note: you cannot subtract a ToyStoreItem if the quantity is 0 }

//Receives the code of a ToyStoreItem and returns the quantity public int checkQuantity(String code){ // TO DO }

//Receives a ToyStoreItem code and returns the index where the ToyStoreItem is stored //Returns -1 if not found in the inventory public int findToy(String code){ //TO DO }

}

Complete the methods and functionality in the ShoppingCart.java file. In this file you will use the objects ToyStoreItem and ToyStoreInventory to sell toys in your store. The methods in this file will create a menu, that will allow shoppers to add toys to their cart. This class will also update the inventory every time a customer purchases toys. Read the comments in the java file for details.

import java.io.*; import java.util.Scanner; import java.util.*;

public class ShoppingCart { public static void main(String[] args){ //Create an instance of ToyStoreInventory using the given text file. //Initialize the needed variables.

/*Display a menu to: 1. Show list of toys 2. Buy a toy - (i) For this option display the name and code of all the items available in the inventory. (ii) Ask the user for the code and quantity of the desired toy. Check that there is enough quantity in stock for the purchase. If there is not enough toys, print the mesage "The maximum number of this toy you can buy is X" - replace 'X' by the number of available toys of this kind. (iii) Ask the user if s/he is ready to checkout. If yes, go to step 3. If no, go to step 2(ii). 3. Checkout - For this option (a) print the total amount due and (b) subtract the number of purchased toys from the inventory (subtract quantity and not the toy itself). */ } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!