package ObjectOriantedHomeworks;
import java.util.*;
public class testHW3 {
public static void main(String[] args) {
CafeteriaItem cafe = new CafeteriaItem();
cafe.setCafeName("Mapple Cafe");
cafe.setServiceFee(5);
cafe.setTaxRate(8);
Billing b = new Billing();
Scanner input = new Scanner(System.in);
byte ch;
menu(cafe);
while (true) {
ch = input.nextByte();
switch (ch) {
case 1:
b.addItems(new Creal());
System.out.println((new Creal()).getName() + " has been added");
break;
case 2:
b.addItems(new ScambledEggs());
System.out.println((new ScambledEggs()).getName() + " has been added");
break;
case 3:
b.addItems(new Pannini());
System.out.println((new Pannini()).getName() + " has been added");
break;
case 4:
b.addItems(new Chicken());
System.out.println((new Chicken()).getName() + " has been added");
break;
case 5:
b.addItems(new Meat());
System.out.println((new Meat()).getName() + " has been added");
break;
case 6:
b.addItems(new Pasta());
System.out.println((new Pasta()).getName() + " has been added");
break;
case 7:
b.addItems(new Caffe());
System.out.println((new Caffe()).getName() + " has been added");
break;
case 8:
b.addItems(new FruitJuice());
System.out.println((new FruitJuice()).getName() + " has been added");
break;
case 9:
b.addItems(new Tea());
System.out.println((new Tea()).getName() + " has been added");
break;
case 10:
if (b.list.size() == 0) {
System.out.println("Cash register is empty.Payment is fail !!");
break;
} else {
System.out.println(b.toString());
System.exit(0);
}
case 11:
if (b.list.size() != 0) {
b.list.remove(b.list.get(b.list.size() - 1));
System.out.println("Your last chooise has been deleted");
} else
System.out.println("You haven't made a chooise yet !");
break;
case 12:
b.clearCashRegiter();
System.out.println("Cash register has been cleared successfully");
break;
default:
System.out.println("Wrong Chooise !!");
}
}
}
public static void menu(CafeteriaItem cafe) {
String menu = String.format("%s\n%30s\n%28s\n%s\n", "________________________________________________",
cafe.getCafeName().toUpperCase(), "M E N U", "************************************************")
+ String.format("%10s%16s%17s\n\n", "BREAKFAST", "LAUNCH", "BEVERAGES")
+ String.format("%9s%19s%13s\n%7s%18s%22s\n%11s%15s%13s", "1] Creal", "4] Chicken", "7] Caffe",
"2] Egg", "5] Meat", "8] Fruit Juice", "3] Pannini", "6] Pasta", "9] Tea")
+ "\n************************************************\n\n10] Pay it!!\n11] Remove chooise !!\n12] Clear Cash Register !!\n________________________________________________"
+ "\n\n Enter Your Chooise :";
System.out.println(menu);
}
}
class Billing {
ArrayList<CafeteriaItem> list = new ArrayList<>();
public void addItems(CafeteriaItem item) {
if (item instanceof Pasta)
list.add((Pasta) item);
else if (item instanceof Meat)
list.add((Meat) item);
else if (item instanceof Chicken)
list.add((Chicken) item);
else if (item instanceof Creal)
list.add((Creal) item);
else if (item instanceof Pannini)
list.add((Pannini) item);
else if (item instanceof Tea)
list.add((Tea) item);
else if (item instanceof Caffe)
list.add((Caffe) item);
else if (item instanceof ScambledEggs)
list.add((ScambledEggs) item);
else
list.add((FruitJuice) item);
}
public int numberOfItems() {
return list.size();
}
public double totalCost() {
double cost = 0;
for (int i = 0; i < list.size(); i++) {
if (list.get(i) instanceof Pasta)
cost += ((Pasta) list.get(i)).getPrice();
else if (list.get(i) instanceof Meat)
cost += ((Meat) list.get(i)).getPrice();
else if (list.get(i) instanceof Chicken)
cost += ((Chicken) list.get(i)).getPrice();
else if (list.get(i) instanceof Creal)
cost += ((Creal) list.get(i)).getPrice();
else if (list.get(i) instanceof Pannini)
cost += ((Pannini) list.get(i)).getPrice();
else if (list.get(i) instanceof Tea)
cost += ((Tea) list.get(i)).getPrice();
else if (list.get(i) instanceof Caffe)
cost += ((Caffe) list.get(i)).getPrice();
else if (list.get(i) instanceof ScambledEggs)
cost += ((ScambledEggs) list.get(i)).getPrice();
else
cost += ((FruitJuice) list.get(i)).getPrice();
}
return cost;
}
public double totalTax() {
return (totalCost() * list.get(0).getTaxRate()) / 100;
}
public void clearCashRegiter() {
list.clear();
}
public String toString() {
String info = "________________________________________________\n" + "\t\t" + list.get(0).getCafeName() + "\n\t"
+ list.get(0).getAddress() + "\n\n" + list.get(0).getDate().toGMTString()
+ "\n--------------------------------------------------\n\n";
for (int i = 0; i < list.size(); i++) {
if (list.get(i) instanceof Pasta) {
info += ((Pasta) list.get(i)).getName() + String.format("%26s",
((Pasta) list.get(i)).getTaxRate() + " " + ((Pasta) list.get(i)).getPrice() + " $\n");
} else if (list.get(i) instanceof Meat) {
info += ((Meat) list.get(i)).getName() + String.format("%31s",
((Meat) list.get(i)).getTaxRate() + " " + ((Meat) list.get(i)).getPrice() + " $\n");
} else if (list.get(i) instanceof Chicken) {
info += ((Chicken) list.get(i)).getName() + String.format("%20s",
((Chicken) list.get(i)).getTaxRate() + " " + ((Chicken) list.get(i)).getPrice() + " $\n");
} else if (list.get(i) instanceof Creal)
info += ((Creal) list.get(i)).getName() + String.format("%27s",
((Creal) list.get(i)).getTaxRate() + " " + ((Creal) list.get(i)).getPrice() + " $\n");
else if (list.get(i) instanceof Pannini) {
info += ((Pannini) list.get(i)).getName() + String.format("%34s",
((Pannini) list.get(i)).getTaxRate() + " " + ((Pannini) list.get(i)).getPrice() + " $\n");
} else if (list.get(i) instanceof Tea) {
info += ((Tea) list.get(i)).getName() + String.format("%28s",
((Tea) list.get(i)).getTaxRate() + " " + ((Tea) list.get(i)).getPrice() + " $\n");
} else if (list.get(i) instanceof Caffe) {
info += ((Caffe) list.get(i)).getName() + String.format("%30s",
((Caffe) list.get(i)).getTaxRate() + " " + ((Caffe) list.get(i)).getPrice() + " $\n");
} else if (list.get(i) instanceof ScambledEggs) {
info += ((ScambledEggs) list.get(i)).getName()
+ String.format("%27s", ((ScambledEggs) list.get(i)).getTaxRate() + " "
+ ((ScambledEggs) list.get(i)).getPrice() + " $\n");
} else {
info += ((FruitJuice) list.get(i)).getName()
+ String.format("%28s", ((FruitJuice) list.get(i)).getTaxRate() + " "
+ ((FruitJuice) list.get(i)).getPrice() + " $\n");
;
}
}
info += "\nService Fee" + String.format("%25s $", list.get(0).getServiceFee()) + "\n\nKDV"
+ String.format("%33s $", totalTax()) + "\nTotal Price"
+ String.format("%26s $", (totalCost() + totalTax() + list.get(0).getServiceFee()))
+ "\n-----------------------------------------------" + "\n\tthank you for choosing us "
+ "\n________________________________________________" + "\n\n\t Payment is accomplished";
return info;
}
}
class CafeteriaItem {
private double serviceFee;
private double taxRate;
private String cafeName;
private String address = "2390 West Flagler Street\n\t Miami, FL 33135-1525";
private Date date;
public CafeteriaItem(String Cafename) {
this.cafeName = Cafename;
serviceFee = 5;
taxRate = 8;
date = new Date();
}
public CafeteriaItem() {
cafeName = "Mapple Cafe";
taxRate = 0.08;
serviceFee = 8;
date = new Date();
}
public double getServiceFee() {
return serviceFee;
}
public void setServiceFee(double serviceFee) {
this.serviceFee = serviceFee;
}
public double getTaxRate() {
return taxRate;
}
public void setTaxRate(double taxRate) {
this.taxRate = taxRate;
}
public String getCafeName() {
return cafeName;
}
public void setCafeName(String cafeName) {
this.cafeName = cafeName;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}
class BreakfastMenu extends CafeteriaItem {
private String name;
private double price;
public BreakfastMenu(String Cafename) {
super(Cafename);
// TODO Auto-generated constructor stub
}
public BreakfastMenu() {
super();
}
}
class LaunchMenu extends CafeteriaItem {
public LaunchMenu(String Cafename) {
super(Cafename);
// TODO Auto-generated constructor stub
}
public LaunchMenu() {
}
}
class BeveragesMenu extends CafeteriaItem {
public BeveragesMenu() {
super();
// TODO Auto-generated constructor stub
}
public BeveragesMenu(String Cafename) {
super(Cafename);
// TODO Auto-generated constructor stub
}
}
class Pannini extends BreakfastMenu {
private String name;
private double price;
public Pannini() {
super("Mapple Caffe");
// TODO Auto-generated constructor stub
name = "Panini";
price = 10;
}
public Pannini(String Cafename) {
super(Cafename);
// TODO Auto-generated constructor stub
name = "Panini";
price = 10;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
class ScambledEggs extends BreakfastMenu {
private String name;
private double price;
public ScambledEggs() {
super("Mapple Caffe");
// TODO Auto-generated constructor stub
name = "Scambled Egg";
price = 2;
}
public ScambledEggs(String Cafename) {
super(Cafename);
// TODO Auto-generated constructor stub
name = "Scambled Egg";
price = 2;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
class Creal extends BreakfastMenu {
private String name;
private double price;
public Creal() {
super("Mapple Caffe");
// TODO Auto-generated constructor stub
name = "Milky Cereal";
price = 1.5;
}
public Creal(String Cafename) {
super(Cafename);
// TODO Auto-generated constructor stub
name = "Milky Cereal";
price = 1.5;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
class Chicken extends LaunchMenu {
private String name;
private double price;
public Chicken() {
super("Mapple Caffe");
// TODO Auto-generated constructor stub
name = "Curry Sauced Chicken";
price = 12;
}
public Chicken(String Cafename) {
super(Cafename);
// TODO Auto-generated constructor stub
name = "Curry Sauced Chicken";
price = 12;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
class Meat extends LaunchMenu {
private String name;
private double price;
public Meat() {
super("Mapple Caffe");
// TODO Auto-generated constructor stub
name = "Beefsteak";
price = 20;
}
public Meat(String Cafename) {
super(Cafename);
// TODO Auto-generated constructor stub
name = "Beefsteak";
price = 20;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
class Pasta extends LaunchMenu {
private String name;
private double price;
public Pasta() {
super("Mapple Caffe");
// TODO Auto-generated constructor stub
name = "Ricotta Paste";
price = 3;
}
public Pasta(String Cafename) {
super(Cafename);
// TODO Auto-generated constructor stub
name = "Ricotto Pasta";
price = 3;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
class Caffe extends BeveragesMenu {
private String name;
private double price;
public Caffe() {
super("Mapple Caffe");
// TODO Auto-generated constructor stub
name = "Americano";
price = 2.5;
}
public Caffe(String Cafename) {
super(Cafename);
// TODO Auto-generated constructor stub
name = "Mocha";
price = 2.5;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
class Tea extends BeveragesMenu {
private String name;
private double price;
public Tea() {
super("Mapple Caffe");
// TODO Auto-generated constructor stub
name = "Turkish Tea";
price = 1.5;
}
public Tea(String Cafename) {
super(Cafename);
// TODO Auto-generated constructor stub
name = "Turkish Tea";
price = 1.5;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
class FruitJuice extends BeveragesMenu {
private String name;
private double price;
public FruitJuice() {
super("Mapple Caffe");
// TODO Auto-generated constructor stub
name = "Apple Juice";
price = 2;
}
public FruitJuice(String Cafename) {
super(Cafename);
// TODO Auto-generated constructor stub
name = "Orange Juice";
price = 2;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}