Commit 6e9a33db authored by ryanw's avatar ryanw

Upload of second assignment

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>FoodOrdering</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Scanner;
public class FoodOderingSystem
{
//format object to better display currency
static NumberFormat cf = NumberFormat.getCurrencyInstance();
//array list for basket items
static ArrayList<Item> basket = new ArrayList<Item>();
static Scanner input = new Scanner(System.in);
static Item pizza = new Item(1, "Pizza", 10, 50);
static Item burger = new Item(2, "Burger", 7, 50);
static Item sandwich = new Item(3, "Sandwich", 5, 50);
static Item water = new Item(4, "Water", 1, 30);
static Item sDrink = new Item(5, "Soft Drink", 2, 30);
static Item tea = new Item(6, "Tea", 2, 20);
static Item coffee = new Item(7, "Coffee", 2, 20);
static Item iceCream = new Item(8, "Ice Cream", 2, 20);
static Item choc = new Item(9, "Chocolate", 2, 20);
static int quantity;
//static double total = 0;
public static void main(String[] args)
{
ItemMenu();
}
//method display menu to the user
public static void ItemMenu()
{
while(true)
{
System.out.println("\t---Welcome to Restaurant Order service---");
System.out.println("\nHere are the items we have available");
System.out.println("Please select from the following: \n");
System.out.println("CODE " + "\tNAME " + "\t\tPRICE" + "\t\tQUANTITY AVAILABLE");
System.out.println("1 " + "\tPizza " + "\t\t" + cf.format(pizza.getItemPrice()) + "\t\t" + pizza.getItemQty()
+ "\n2 " + "\tBurger" + "\t\t" + cf.format(burger.getItemPrice()) + "\t\t" + burger.getItemQty()
+ "\n3 " + "\tSandwich" + "\t" + cf.format(sandwich.getItemPrice()) + "\t\t" + sandwich.getItemQty()
+ "\n4 " + "\tWater " + "\t\t" + cf.format(water.getItemPrice()) + "\t\t" + water.getItemQty()
+ "\n5 " + "\tSoft Drink" + "\t" + cf.format(sDrink.getItemPrice()) + "\t\t" + sDrink.getItemQty()
+ "\n6 " + "\tTea" + "\t\t" + cf.format(tea.getItemPrice()) + "\t\t" + tea.getItemQty()
+ "\n7 " + "\tCoffee" + "\t\t" + cf.format(coffee.getItemPrice()) + "\t\t" + coffee.getItemQty()
+ "\n8 " + "\tIce Cream" + "\t" + cf.format(iceCream.getItemPrice()) + "\t\t" + iceCream.getItemQty()
+ "\n9 " + "\tChocolate" + "\t" + cf.format(choc.getItemPrice()) + "\t\t" + choc.getItemQty());
System.out.print("\nSelection: ");
int choice = input.nextInt();
if(choice == 1)
{
basket.add(pizza);
}
else if(choice == 2)
basket.add(burger);
else if(choice == 3)
basket.add(sandwich);
else if(choice == 4)
basket.add(water);
else if(choice == 5)
basket.add(sDrink);
else if(choice == 6)
basket.add(tea);
else if(choice == 7)
basket.add(coffee);
else if(choice == 8)
basket.add(iceCream);
else if(choice == 9)
basket.add(choc);
System.out.print("Please enter the quantity you wish to purchase: ");
quantity = input.nextInt();
//reduces stock amount
for (int i = 0; i < basket.size(); i++)
{
basket.get(i).itemQty = basket.get(i).itemQty - quantity;
}
Continue();
}//end of while loop
}//end of main menu method
//method to remove items from the basket
public static void RemoveItem()
{
for (int i = 0; i < basket.size(); i++)//for loop to display selected items
{
System.out.println(basket.get(i).itemCode + " " + basket.get(i).itemName + " " + basket.get(i).itemPrice);
}
System.out.println("Please select the item code of the item you wish to remove: ");
int remove = input.nextInt();
for (int i = 0; i < basket.size(); i++)//second for loop to remove items from the basket array list
{
if (basket.get(i).itemCode == remove)
{
basket.remove(i);
}
Continue();
}
}
//method to display items currently in the basket
public static void ViewBasket()
{
System.out.println("---Basket Items---");
System.out.println("\nCODE " + "\tNAME " + "\t\tPRICE" + "\tQUANTITY SELECTED");
//for loop to display selected items
for (int i = 0; i < basket.size(); i++)
{
System.out.println(basket.get(i).itemCode + " \t" + basket.get(i).itemName +
" \t" + cf.format(basket.get(i).itemPrice) + " \tx" + quantity);
}
Continue();
}
//method to display order info and process a payment
public static void Checkout()
{
double total = 0;
//displays items in the basket
System.out.println("---ORDER RECIPT---");
System.out.println("\nHere are your selections: ");
for (int i = 0; i < basket.size(); i++)
{
System.out.println(basket.get(i).itemName + " x " + quantity);
}
//get total amount of items in the basket
for (int i = 0; i < basket.size(); i++)
{
total = total + (basket.get(i).getItemPrice() * quantity);
}
System.out.println("Your total is: " + cf.format(total));
System.out.println("\n---ORDER RECIPT---");
System.out.println("\n---PAYMENT---");
System.out.print("Please enter your payment here: ");
double payment = input.nextDouble();
if(payment > total)
{
double change = payment - total;
System.out.println("\nPayment successful. Here is your change " + cf.format(change) + " Thank you.");
}
else if(payment < total)
{
double extra = total - payment;
System.out.println("\nInsufficient funds. Item total was " + cf.format(total) + "You require " + cf.format(extra) + " more.");
}
else if(payment == total)
{
System.out.println("\nHere are you items. Thank you for ordering");
}
System.out.println("\nTo order again press Y. To exit press N.");
String choice = input.next();
if(choice.equals("y"))
{
basket.clear();
ItemMenu();
}
else
System.out.println("Thank you, goodbye");
System.exit(0);
basket.clear();
}//end of checkout method
//method to allow user to navigate the menu system
public static void Continue()
{
System.out.println("\n1 - Select Items"
+ "\n2 - Remove items from basket"
+ "\n3 - View basket"
+ "\n4 - Go to checkout"
+ "\n5 - Exit");
System.out.println("Selection: ");
int choiceTwo = input.nextInt();
switch (choiceTwo)
{
case 1:
ItemMenu();
break;
case 2:
RemoveItem();
break;
case 3:
ViewBasket();
break;
case 4:
Checkout();
break;
case 5:
System.out.println("Thank you, Goodbye");
System.exit(0);
break;
default:
break;
}
}
}
public class Item
{
int itemCode;
String itemName;
double itemPrice;
int itemQty;
//Item class constructor
public Item(int itemCode, String itemName, double itemPrice, int itemQty)
{
this.itemCode = itemCode;
this.itemName = itemName;
this.itemPrice = itemPrice;
this.itemQty = itemQty;
}
//get and set methods for all the class fields
public int getItemCode()
{
return itemCode;
}
public void setItemCode(int itemCode)
{
this.itemCode = itemCode;
}
public String getItemName()
{
return itemName;
}
public void setItemName(String itemName)
{
this.itemName = itemName;
}
public double getItemPrice()
{
return itemPrice;
}
public void setItemPrice(double itemPrice)
{
this.itemPrice = itemPrice;
}
public int getItemQty()
{
return itemQty;
}
public void setItemQty(int itemQty)
{
this.itemQty = itemQty;
}
public void reduceStock(int quantity)
{
itemQty = itemQty - quantity;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment