import java.util.*;
import java.text.*;
public class shopcal
{
public static void main (String[] args) throws Exception
{
Item[] items = new Item[100];
DecimalFormat fmt = new DecimalFormat("0.00");
int numItems = 0;
while (true)
{
// Get the top-level menu choice
String choice = getMenuChoice();
if (choice.equals("1"))
{
// Calculate shopping calculator choice
// get item description
String description = getItemDescription(numItems);
// get total item price
double price = getItemPrice();
// get the quantity of that item
int number = getItemQuantity();
// Set only if confirmation is recieved
if (getConfirmation())
{
// create a new item and add it
items[numItems] = new Item(description, price, number);
// TODO: increase the number of items
}
}
else if (choice.equals("2"))
{
// display total expenditure choice
System.out.println("Display Item's Individual Cost & Total Cost");
System.out.println("=============================================");
for (int i = 0; i < numItems; i++)
{
// TODO: what should be printed out for each item?
// use items[i].(attribute goes here) to access the item's attributes
// ex: items[i].description gets the item's description
}
}
else if (choice.equals("3"))
{
// quit choice
return;
}
else
{
// invalid menu choice
// TODO: print out an error message if choice was not 1, 2, or 3
}
}
}
public static String getMenuChoice ()
{
Scanner input = new Scanner(System.in);
System.out.println("****Shopping EXpenditure Calculator****");
System.out.println("1. Calculate Shopping Calculator");
System.out.println("2. Display Total Expenditure");
System.out.println("3. Exit");
System.out.println("***************************************");
System.out.print("Please Enter Your Choice: ");
return input.nextLine();
}
public static String getItemDescription (int itemNum)
{
// here's a completed example of how getting each attribute should look like
Scanner input = new Scanner(System.in);
System.out.println("Please ener detials for item " + itemNum);
System.out.println("==================================");
System.out.print("Item 1's Description is : ");
return input.nextLine();
}
public static double getItemPrice ()
{
// TODO: finish this method
Scanner input = new Scanner(System.in);
double price = 0;
// TODO: print out what you want to ask the user
// TODO: read in from scanner
// TODO: return the price (as double)
return price;
}
public static int getItemQuantity ()
{
// TODO: finish this method
Scanner input = new Scanner(System.in);
int quantity = 0;
// TODO: print out what you want to ask the user
// TODO: read in from scanner
// TODO: return the quantity (as int)
return quantity;
}
public static boolean getConfirmation ()
{
// TODO: finish this method
Scanner input = new Scanner(System.in);
String read = "";
// TODO: print out what you want to ask the user
// TODO: read in from scanner
// TODO: check to see if y/n, return appropriate true (y) or false (n)
if (read.equals("y"))
{
return false;
}
else if (read.equals("n"))
{
return false;
}
else
{
// TODO: handle invalid input
// throw an exception
throw new RuntimeException();
}
}
}