I am working on an inventory program where I have the user input some information about a product they would like to buy. I then use an if else if statement to create the object depending what the user typed in. However at the end of the program I want to recall that object, but don't know how to. The program stores it, I can't assign it as a variable so what do I do?
System.out.println("Welcome to our hardware shop. We have three items in stock: \n" + "Wrench CMMT12001\n"
+ "Power Drill 12v\n"
+ "Shovel D-Handle\n"
+ "Which product would you like to buy?");
product = keyboard.nextLine();
System.out.println("How many items of this product would you like?");
items = keyboard.nextInt();
System.out.println("What is the date (00/00/0000) ");
date = keyboard.nextLine();
int dayOfYear = dayOfYear(date);
if (product.equals("Wrench CMMT12001")) {
Products wrench = new Products(productXID, product, productXPrice, "X", items, dayOfYear);
}
else if (product.equals("Power Drill 12v")) {
Products drill = new Products(productYID, product, productYPrice, "Y", items, dayOfYear);
}
else if (product.equals("Shovel D-Handle")) {
Products shovel = new Products(productZID, product, productZPrice, "Z", items, dayOfYear);
}
else
System.out.println("You did not enter a product.");