Module 2
Module 2
*;
}
while ( keepShopping.equalsIgnoreCase( "y" ) );
getPrompt(items,no_items,price,total);
}
System.out.println("Products\t\tQuantity\t\tPrice");
for(int i=0;i<items.size();i++) {
System.out.println(i+". "+items.get(i) + "\t\t"+no_items.get(i)
+"\t\t\t"+price.get(i));
total +=no_items.get(i)*price.get(i);
}
System.out.println("The total cost is : "+total);
System.out.print("Do you want to pruchase the products (true/false)?
");
is_paid = input.nextBoolean();
if(is_paid == true) {
System.out.println("Purchase successful.");
}else {
System.out.println("Purchase denied");
}
}
System.out.println("Products\t\tQuantity\t\tPrice");
for(int i=0;i<items.size();i++) {
System.out.println(i+". "+items.get(i) + "\t\t"+no_items.get(i)
+"\t\t\t"+price.get(i));
}
System.out.print("Enter the index you want to remove : ");
remove = input.nextInt();
items.remove(remove);
no_items.remove(remove);
price.remove(remove);
getPrompt(items,no_items,price,total);
}
getPrompt(items,no_items,price,total);
}
static void getUpdate(List<String> items, List<Integer> no_items,
List<Float> price, float total) {
Scanner input = new Scanner(System.in);
String Items;
float Price;
int update, No_item;
items.set(update, Items);
no_items.set(update, No_item);
price.set(update, Price);
getPrompt(items,no_items,price,total);
}
static void getPrompt(List<String> items, List<Integer> no_items,
List<Float> price, float total) {
if(prompt.equals("add")) {
getAdd(items,no_items,price,total);
}else if(prompt.equals("remove")) {
getRemove(items,no_items,price,total);
}else if(prompt.equals("done")){
getTotal(items,no_items,price,total);
}else if(prompt.equals("update")) {
getUpdate(items,no_items,price,total);
}
}
}