Skip to content

Instantly share code, notes, and snippets.

@naijab
Created December 24, 2018 21:54
Show Gist options
  • Save naijab/f3e3aeda51c951b2b9aae490d746fb0c to your computer and use it in GitHub Desktop.
Save naijab/f3e3aeda51c951b2b9aae490d746fb0c to your computer and use it in GitHub Desktop.
Restaurant Java
public class Customer {
private String cus_id;
private String cus_name;
private String cus_gender;
private String cus_type;
public Customer() {
}
public Customer(String cus_id, String cus_name, String cus_gender, String cus_type) {
this.cus_id = cus_id;
this.cus_name = cus_name;
this.cus_gender = cus_gender;
this.cus_type = cus_type;
}
public String getCus_id() {
return cus_id;
}
public void setCus_id(String cus_id) {
this.cus_id = cus_id;
}
public String getCus_name() {
return cus_name;
}
public void setCus_name(String cus_name) {
this.cus_name = cus_name;
}
public String getCus_gender() {
return cus_gender;
}
public void setCus_gender(String cus_gender) {
this.cus_gender = cus_gender;
}
public String getCus_type() {
return cus_type;
}
public void setCus_type(String cus_type) {
this.cus_type = cus_type;
}
@Override
public String toString() {
return "Customer{" + "cus_id=" + cus_id + ", cus_name=" + cus_name + ", cus_gender=" + cus_gender + ", cus_type=" + cus_type + '}';
}
public class Item {
private String item_id;
private String item_name;
private float item_price;
private int item_time;
public Item() {
}
public Item(String item_id, String item_name, int item_price, int item_time) {
this.item_id = item_id;
this.item_name = item_name;
this.item_price = item_price;
this.item_time = item_time;
}
public int getItem_time() {
return item_time;
}
public void setItem_time(int item_time) {
this.item_time = item_time;
}
public String getItem_id() {
return item_id;
}
public void setItem_id(String item_id) {
this.item_id = item_id;
}
public String getItem_name() {
return item_name;
}
public void setItem_name(String item_name) {
this.item_name = item_name;
}
public float getItem_price() {
return item_price;
}
public void setItem_price(int item_price) {
this.item_price = item_price;
}
@Override
public String toString() {
return "Item{" + "item_id=" + item_id + ", item_name=" + item_name + ", item_price=" + item_price + ", item_time=" + item_time + '}';
}
}
public class Restaurant {
public static void main(String[] args) {
Customer c1 = new Customer("C01", "Aran", "Male", "Vip");
Customer c2 = new Customer("C02", "Aranya", "Female", "Normal");
Customer c3 = new Customer("C03", "Arthit", "Female", "Normal");
Item i1 = new Item("i01", "Pork Steak", 239, 35);
Item i2 = new Item("i02", "Chicken Teriyaki", 199, 25);
Item i3 = new Item("i03", "Fish an Chips", 179, 30);
Item i4 = new Item("i04", "Beef Strew", 289, 45);
Item i5 = new Item("i05", "Apple pie", 89, 30);
Table t1 = new Table(c1);
Table t2 = new Table(c2);
Table t3 = new Table(c3);
t1.order(i1);
t1.order(i3);
t1.order(i5);
System.out.println(t1.getCus().getCus_gender() + " "
+ t1.getCus().getCus_name() + " have to pay " + t1.getTotalPrice()
+ " bath and wait " + t1.getWaitTime() + " miniutes\n");
t2.order(i2);
t2.order(i4);
System.out.println(t2.getCus().getCus_gender() + " "
+ t2.getCus().getCus_name() + " have to pay " + t2.getTotalPrice()
+ " bath and wait " + t2.getWaitTime() + " miniutes\n");
t3.order(i1);
t3.order(i4);
t3.order(i5);
System.out.println(t3.getCus().getCus_gender() + " "
+ t3.getCus().getCus_name() + " have to pay " + t3.getTotalPrice()
+ " bath and wait " + t3.getWaitTime() + " miniutes\n");
}
}
public class Table {
private Customer cus;
private Item[] items;
private int orderCount;
public Table(Customer cus) {
this.items = new Item[10];
this.cus = cus;
}
public void order(Item item) {
if (orderCount < 10) {
System.out.println(this.cus.getCus_name() + " order " + item.getItem_name());
this.items[orderCount] = item;
orderCount++;
}
}
public float getTotalPrice() {
float sum = 0;
float discount = 0;
for (Item item : items) {
if (item != null) {
sum += item.getItem_price();
}
}
if (cus.getCus_type().equals("Vip")) {
discount = (10 * sum) / 100;
sum = sum - discount;
}
return sum;
}
public int getWaitTime() {
return items[0].getItem_time();
}
public Customer getCus() {
return cus;
}
public void setCus(Customer cus) {
this.cus = cus;
}
public Item[] getItems() {
return items;
}
public void setItems(Item[] items) {
this.items = items;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment