From 44f0b4a937181d5f1716ef9c23b556363d15525a Mon Sep 17 00:00:00 2001 From: Ashkan Asef Date: Wed, 24 Apr 2024 13:20:07 -0700 Subject: [PATCH 01/11] boshghab --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 44540b9..4f011c9 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,4 @@ ### ددلاین تمرین تا روز یکشنبه 9 اردیبهشت 1403 ساعت 11.5 صبح می باشد. ### موفق باشید :) + boos boos \ No newline at end of file From 0cde3583b8f06a4f1ed2d1645598375a76264282 Mon Sep 17 00:00:00 2001 From: Ashkan Asef Date: Wed, 24 Apr 2024 13:29:27 -0700 Subject: [PATCH 02/11] removed alksdjf;lkasdfjkl --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4f011c9..c6270e1 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,4 @@ ### ددلاین تمرین تا روز یکشنبه 9 اردیبهشت 1403 ساعت 11.5 صبح می باشد. ### موفق باشید :) - boos boos \ No newline at end of file + boooos \ No newline at end of file From 478193e5bc291133c5655c386500aea97d887cb5 Mon Sep 17 00:00:00 2001 From: Ashkan Asef Date: Wed, 24 Apr 2024 13:43:51 -0700 Subject: [PATCH 03/11] ialsdkfj --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c6270e1..2b13dc5 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,6 @@ ### در نهایت با ارسال پول ریکوئست به صفحه تمرین کد شما تصحیح خواهد شد. -### ددلاین تمرین تا روز یکشنبه 9 اردیبهشت 1403 ساعت 11.5 صبح می باشد. ### موفق باشید :) - boooos \ No newline at end of file + boooos +nemidanam etelai nadaram \ No newline at end of file From 3eac9a450fd285dc9e38f3f231535fe90ef8104b Mon Sep 17 00:00:00 2001 From: Ashkan Asef Date: Wed, 24 Apr 2024 13:47:55 -0700 Subject: [PATCH 04/11] skdjflaksdjf --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2b13dc5..5cb91d4 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,5 @@ ### موفق باشید :) boooos -nemidanam etelai nadaram \ No newline at end of file +nemidanam etelai nadaram +man aslkdfjlsa;dfkjfkasd \ No newline at end of file From 6ddc85fe7eb36ebabfd2174418d2d996069b9dd1 Mon Sep 17 00:00:00 2001 From: Ashkan Asef Date: Fri, 3 May 2024 04:04:08 -0700 Subject: [PATCH 05/11] added class Address --- .idea/.gitignore | 3 +++ .idea/hw5.iml | 9 +++++++ .idea/misc.xml | 6 +++++ .idea/modules.xml | 8 +++++++ .idea/vcs.xml | 6 +++++ README.md | 3 --- first/restaurant/Address.java | 44 +++++++++++++++++++++++++++++++++++ first/restaurant/classhw.java | 43 ++++++++++++++++++++++++++++++++++ 8 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/hw5.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 first/restaurant/Address.java create mode 100644 first/restaurant/classhw.java diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/hw5.iml b/.idea/hw5.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/hw5.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6f29fee --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..8f8a12d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 5cb91d4..0a012f7 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,3 @@ ### در نهایت با ارسال پول ریکوئست به صفحه تمرین کد شما تصحیح خواهد شد. ### موفق باشید :) - boooos -nemidanam etelai nadaram -man aslkdfjlsa;dfkjfkasd \ No newline at end of file diff --git a/first/restaurant/Address.java b/first/restaurant/Address.java new file mode 100644 index 0000000..046b190 --- /dev/null +++ b/first/restaurant/Address.java @@ -0,0 +1,44 @@ +public class Address { + + private double latitude; + private double longitude; + private String written_address; + + public Address(double latitude, double longitude, String writtenAddress) { + this.latitude = latitude; + this.longitude = longitude; + this.writtenAddress = writtenAddress; + } + + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public String getWritten_address() { + return writtenAddress; + } + + public void setWrittenAddress(String written_address) { + this.writtenAddress = written_address; + } + + public double distanceFrom(Address Address2) { + double la_distance = this.latitude - Address2.latitude; + double lo_distance = this.longitude - Address2.longitude; + double distance = Math.sqrt(Math.pow(la_distance, 2) + Math.pow(lo_distance, 2)); + + return distance; + } +} \ No newline at end of file diff --git a/first/restaurant/classhw.java b/first/restaurant/classhw.java new file mode 100644 index 0000000..c6886fb --- /dev/null +++ b/first/restaurant/classhw.java @@ -0,0 +1,43 @@ +class Customer{ + +} +class Food{ + +} +class item{ + private final Food food; + private final int count; + private final String description; + public item(Food food1, int count1, String description1){ + this.food = food1; + this.count = count1; + this.description = description1; + } + + public Food getFood(){ + return food; + } + public int getCount(){ + return count; + } + public String getDescription(){ + return description; + } +} + +class Invoice{ + private int state; + private Customer customer; + public int getState(){ + return state; + } + public Invoice(Customer customer1){ + this.customer = customer1; + this.state = -1; + } + + public int additem(item item){ + + } + +} \ No newline at end of file From 886db5988a666bbfe47ffcf68cdcea65aaff049d Mon Sep 17 00:00:00 2001 From: Ashkan Asef Date: Fri, 3 May 2024 04:17:04 -0700 Subject: [PATCH 06/11] added Customer class --- first/restaurant/Customer.java | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 first/restaurant/Customer.java diff --git a/first/restaurant/Customer.java b/first/restaurant/Customer.java new file mode 100644 index 0000000..89c53a2 --- /dev/null +++ b/first/restaurant/Customer.java @@ -0,0 +1,35 @@ +public class Customer { + private static int newId = 1; + private final int id; + private String name; + private Address address; + + public Customer(String name, Address address) { + this.id = newId; + newId++; + this.name = name; + this.address = address; + } + + public int getCustomerNumber() { + return id; + } + + // no set for customer number as it is final + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Address getAddress() { + return address; + } + + public void setAddress(Address address) { + this.address = address; + } +} \ No newline at end of file From fb3646345ca4c48286179b3bee10f3bcd6791316 Mon Sep 17 00:00:00 2001 From: Ashkan Asef Date: Fri, 3 May 2024 04:23:57 -0700 Subject: [PATCH 07/11] added Food class --- first/restaurant/Food.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 first/restaurant/Food.java diff --git a/first/restaurant/Food.java b/first/restaurant/Food.java new file mode 100644 index 0000000..8281a04 --- /dev/null +++ b/first/restaurant/Food.java @@ -0,0 +1,26 @@ +import java.util.Vector; + +public class Food { + + private Vector menu = new Vector<>(); + private final String name; + private final int price; + + public Food(String name, int price) { + this.name = name; + this.price = price; + menu.add(this); + } + + public static Vector getMenu() { + return menu; + } + + public String getName() { + return name; + } + + public int getPrice() { + return price; + } +} \ No newline at end of file From 504ee0d90a64508647624e28cc80381ae40703a3 Mon Sep 17 00:00:00 2001 From: Ashkan Asef Date: Fri, 3 May 2024 04:32:08 -0700 Subject: [PATCH 08/11] added Item class --- first/restaurant/Item.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 first/restaurant/Item.java diff --git a/first/restaurant/Item.java b/first/restaurant/Item.java new file mode 100644 index 0000000..1e2a4bd --- /dev/null +++ b/first/restaurant/Item.java @@ -0,0 +1,24 @@ +public class Item { + + private final Food food; + private final int count; + private final String description; + + public Item(Food food, int count, String description) { + this.food = food; + this.count = count; + this.description = description; + } + + public Food getFood() { + return food; + } + + public int getCount() { + return count; + } + + public String getDescription() { + return description; + } +} \ No newline at end of file From 955e85be483a39e3cc8a8a87b49d00d206d427ec Mon Sep 17 00:00:00 2001 From: Ashkan Asef Date: Fri, 3 May 2024 04:59:36 -0700 Subject: [PATCH 09/11] added Invoice class --- first/restaurant/Invoice.java | 75 +++++++++++++++++++++++++++++++++++ first/restaurant/Item.java | 2 +- first/restaurant/classhw.java | 43 -------------------- 3 files changed, 76 insertions(+), 44 deletions(-) create mode 100644 first/restaurant/Invoice.java delete mode 100644 first/restaurant/classhw.java diff --git a/first/restaurant/Invoice.java b/first/restaurant/Invoice.java new file mode 100644 index 0000000..17302c5 --- /dev/null +++ b/first/restaurant/Invoice.java @@ -0,0 +1,75 @@ +import java.util.Vector; + +public class Invoice { + + private static final float tax_rate = 0.094f; + private int state; + private final Customer customer; + private final Vector items; + private float totalPrice; + + public Invoice(Customer customer) { + this.state = -1; + this.customer = customer; + this.items = new Vector<>(); + this.totalPrice = 0.0f; + } + + public int getState() { + return state; + } + + public Customer getCustomer() { + return customer; + } + + public boolean addItem(Item item) { + if (state == -1) { + items.add(item); + calculateTotalPrice(); + return true; + } + else { + return false; + } + } + + public boolean removeItem(Item item) { + int i = 0; + if (state == -1) { + for (Item currItem : items) { + if (currItem.getFood().equals(item.getFood())) { + items.remove(i); + calculateTotalPrice(); + return true; + } + i++; + } + } + return false; + } + + public void nextStage() { + state++; + + } + + public Vector getItems() { + return items; + } + + public int getTotalPrice() { + return (int) Math.ceil(totalPrice); + } + + private void calculateTotalPrice() { + totalPrice = 0.0f; + for (Item item : items) { + // add up all prices + totalPrice += item.getCount() * item.getFood().getPrice(); + } + // totalprice + calculated tax + totalPrice += totalPrice * tax_rate; + + } +} \ No newline at end of file diff --git a/first/restaurant/Item.java b/first/restaurant/Item.java index 1e2a4bd..34e92f3 100644 --- a/first/restaurant/Item.java +++ b/first/restaurant/Item.java @@ -3,7 +3,7 @@ public class Item { private final Food food; private final int count; private final String description; - + public Item(Food food, int count, String description) { this.food = food; this.count = count; diff --git a/first/restaurant/classhw.java b/first/restaurant/classhw.java deleted file mode 100644 index c6886fb..0000000 --- a/first/restaurant/classhw.java +++ /dev/null @@ -1,43 +0,0 @@ -class Customer{ - -} -class Food{ - -} -class item{ - private final Food food; - private final int count; - private final String description; - public item(Food food1, int count1, String description1){ - this.food = food1; - this.count = count1; - this.description = description1; - } - - public Food getFood(){ - return food; - } - public int getCount(){ - return count; - } - public String getDescription(){ - return description; - } -} - -class Invoice{ - private int state; - private Customer customer; - public int getState(){ - return state; - } - public Invoice(Customer customer1){ - this.customer = customer1; - this.state = -1; - } - - public int additem(item item){ - - } - -} \ No newline at end of file From a2ab8f1e97e40e521524b04408b1c3be85e218cd Mon Sep 17 00:00:00 2001 From: Ashkan Asef Date: Fri, 3 May 2024 05:33:46 -0700 Subject: [PATCH 10/11] added main and last class --- Restaurant/.gitignore | 29 ++++++++++++++ Restaurant/.idea/.gitignore | 3 ++ Restaurant/.idea/misc.xml | 6 +++ Restaurant/.idea/modules.xml | 8 ++++ Restaurant/.idea/vcs.xml | 6 +++ Restaurant/Restaurant.iml | 11 ++++++ Restaurant/src/Address.java | 44 +++++++++++++++++++++ Restaurant/src/Customer.java | 35 +++++++++++++++++ Restaurant/src/Food.java | 26 +++++++++++++ Restaurant/src/Invoice.java | 75 ++++++++++++++++++++++++++++++++++++ Restaurant/src/Item.java | 31 +++++++++++++++ Restaurant/src/Main.java | 51 ++++++++++++++++++++++++ first/restaurant/Main.java | 0 13 files changed, 325 insertions(+) create mode 100644 Restaurant/.gitignore create mode 100644 Restaurant/.idea/.gitignore create mode 100644 Restaurant/.idea/misc.xml create mode 100644 Restaurant/.idea/modules.xml create mode 100644 Restaurant/.idea/vcs.xml create mode 100644 Restaurant/Restaurant.iml create mode 100644 Restaurant/src/Address.java create mode 100644 Restaurant/src/Customer.java create mode 100644 Restaurant/src/Food.java create mode 100644 Restaurant/src/Invoice.java create mode 100644 Restaurant/src/Item.java create mode 100644 Restaurant/src/Main.java create mode 100644 first/restaurant/Main.java diff --git a/Restaurant/.gitignore b/Restaurant/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/Restaurant/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Restaurant/.idea/.gitignore b/Restaurant/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Restaurant/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Restaurant/.idea/misc.xml b/Restaurant/.idea/misc.xml new file mode 100644 index 0000000..779255b --- /dev/null +++ b/Restaurant/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Restaurant/.idea/modules.xml b/Restaurant/.idea/modules.xml new file mode 100644 index 0000000..1703cce --- /dev/null +++ b/Restaurant/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Restaurant/.idea/vcs.xml b/Restaurant/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Restaurant/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Restaurant/Restaurant.iml b/Restaurant/Restaurant.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Restaurant/Restaurant.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Restaurant/src/Address.java b/Restaurant/src/Address.java new file mode 100644 index 0000000..7396d41 --- /dev/null +++ b/Restaurant/src/Address.java @@ -0,0 +1,44 @@ +public class Address { + + private double latitude; + private double longitude; + private String written_address; + + public Address(double latitude, double longitude, String writtenAddress) { + this.latitude = latitude; + this.longitude = longitude; + this.written_address = writtenAddress; + } + + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public String getWritten_address() { + return written_address; + } + + public void setWrittenAddress(String written_address) { + this.written_address = written_address; + } + + public double distanceFrom(Address Address2) { + double la_distance = this.latitude - Address2.latitude; + double lo_distance = this.longitude - Address2.longitude; + double distance = Math.sqrt(Math.pow(la_distance, 2) + Math.pow(lo_distance, 2)); + + return Math.round(distance * 100000.0) / 100000.0; + } +} \ No newline at end of file diff --git a/Restaurant/src/Customer.java b/Restaurant/src/Customer.java new file mode 100644 index 0000000..89c53a2 --- /dev/null +++ b/Restaurant/src/Customer.java @@ -0,0 +1,35 @@ +public class Customer { + private static int newId = 1; + private final int id; + private String name; + private Address address; + + public Customer(String name, Address address) { + this.id = newId; + newId++; + this.name = name; + this.address = address; + } + + public int getCustomerNumber() { + return id; + } + + // no set for customer number as it is final + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Address getAddress() { + return address; + } + + public void setAddress(Address address) { + this.address = address; + } +} \ No newline at end of file diff --git a/Restaurant/src/Food.java b/Restaurant/src/Food.java new file mode 100644 index 0000000..90cfe2a --- /dev/null +++ b/Restaurant/src/Food.java @@ -0,0 +1,26 @@ +import java.util.Vector; + +public class Food { + + private static Vector menu = new Vector<>(); + private final String name; + private final int price; + + public Food(String name, int price) { + this.name = name; + this.price = price; + menu.add(this); + } + + public static Vector getMenu() { + return menu; + } + + public String getName() { + return name; + } + + public int getPrice() { + return price; + } +} \ No newline at end of file diff --git a/Restaurant/src/Invoice.java b/Restaurant/src/Invoice.java new file mode 100644 index 0000000..17302c5 --- /dev/null +++ b/Restaurant/src/Invoice.java @@ -0,0 +1,75 @@ +import java.util.Vector; + +public class Invoice { + + private static final float tax_rate = 0.094f; + private int state; + private final Customer customer; + private final Vector items; + private float totalPrice; + + public Invoice(Customer customer) { + this.state = -1; + this.customer = customer; + this.items = new Vector<>(); + this.totalPrice = 0.0f; + } + + public int getState() { + return state; + } + + public Customer getCustomer() { + return customer; + } + + public boolean addItem(Item item) { + if (state == -1) { + items.add(item); + calculateTotalPrice(); + return true; + } + else { + return false; + } + } + + public boolean removeItem(Item item) { + int i = 0; + if (state == -1) { + for (Item currItem : items) { + if (currItem.getFood().equals(item.getFood())) { + items.remove(i); + calculateTotalPrice(); + return true; + } + i++; + } + } + return false; + } + + public void nextStage() { + state++; + + } + + public Vector getItems() { + return items; + } + + public int getTotalPrice() { + return (int) Math.ceil(totalPrice); + } + + private void calculateTotalPrice() { + totalPrice = 0.0f; + for (Item item : items) { + // add up all prices + totalPrice += item.getCount() * item.getFood().getPrice(); + } + // totalprice + calculated tax + totalPrice += totalPrice * tax_rate; + + } +} \ No newline at end of file diff --git a/Restaurant/src/Item.java b/Restaurant/src/Item.java new file mode 100644 index 0000000..aa5db83 --- /dev/null +++ b/Restaurant/src/Item.java @@ -0,0 +1,31 @@ +public class Item { + + private final Food food; + private final int count; + private final String description; + + public Item(Food food, int count, String description) { + this.food = food; + this.count = count; + this.description = description; + } + + public Item(Food food, int count) { + this.food = food; + this.count = count; + // empty + this.description = "-"; + } + + public Food getFood() { + return food; + } + + public int getCount() { + return count; + } + + public String getDescription() { + return description; + } +} \ No newline at end of file diff --git a/Restaurant/src/Main.java b/Restaurant/src/Main.java new file mode 100644 index 0000000..b5607a7 --- /dev/null +++ b/Restaurant/src/Main.java @@ -0,0 +1,51 @@ +public static void main(String[] args) { + Address a1 = new Address(2, 3, "Lahijan"); + Address a2 = new Address(5, 6, "Tehran"); + + System.out.println("\n--------------------------------------\n"); + System.out.println("Distance From Address a1 to a2 is: " + a1.distanceFrom(a2)); + System.out.println("\n--------------------------------------\n"); + + Customer c1 = new Customer("MAMAD", a1); + Customer c2 = new Customer("ALI", a2); + + System.out.println("First Customer's ID: " + c1.getCustomerNumber()); + System.out.println("Second Customer's ID: " + c2.getCustomerNumber()); + + Food f1 = new Food("BURGER", 130); + Food f2 = new Food("PIZZA", 200); + Food f3 = new Food("PASTA", 110); + + System.out.println("\n--------------------------------------\n"); + + for (int i = 0; i < Food.getMenu().size(); i++) { + System.out.println("Food Name: " + Food.getMenu().get(i).getName()); + } + + System.out.println("\n--------------------------------------\n"); + + Item it1 = new Item(f1, 2); + Item it2 = new Item(f2, 3, "MORE SAUCE"); + Item it3 = new Item(f3, 1); + + Invoice inv = new Invoice(c1); + + if (inv.addItem(it1) && inv.addItem(it2)) System.out.println("Items added successfully"); + else System.out.println("Items could not be added"); + + if (inv.removeItem(it3)) System.out.println("Item removed successfully"); + else System.out.println("Failed to remove item (item doesn't exist in invoice)"); + + inv.nextStage(); + + System.out.println("Current state: " + inv.getState()); + + System.out.println("\n--------------------------------------\n"); + + for (int i = 0; i < inv.getItems().size(); i++) { + Item it = inv.getItems().get(i); + System.out.println("Food Name: " + it.getFood().getName() + " | Food Description: " + it.getDescription()); + } + + System.out.println("Total price: " + inv.getTotalPrice()); +} \ No newline at end of file diff --git a/first/restaurant/Main.java b/first/restaurant/Main.java new file mode 100644 index 0000000..e69de29 From 5b4bc3de07360afb3e64875b76b1411c25648f0d Mon Sep 17 00:00:00 2001 From: Ashkan Asef Date: Sat, 4 May 2024 09:02:50 -0700 Subject: [PATCH 11/11] final touch --- first/restaurant/Address.java | 8 +++--- first/restaurant/Food.java | 2 +- first/restaurant/Item.java | 7 +++++ first/restaurant/Main.java | 51 +++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 5 deletions(-) diff --git a/first/restaurant/Address.java b/first/restaurant/Address.java index 046b190..7396d41 100644 --- a/first/restaurant/Address.java +++ b/first/restaurant/Address.java @@ -7,7 +7,7 @@ public class Address { public Address(double latitude, double longitude, String writtenAddress) { this.latitude = latitude; this.longitude = longitude; - this.writtenAddress = writtenAddress; + this.written_address = writtenAddress; } public double getLatitude() { @@ -27,11 +27,11 @@ public void setLongitude(double longitude) { } public String getWritten_address() { - return writtenAddress; + return written_address; } public void setWrittenAddress(String written_address) { - this.writtenAddress = written_address; + this.written_address = written_address; } public double distanceFrom(Address Address2) { @@ -39,6 +39,6 @@ public double distanceFrom(Address Address2) { double lo_distance = this.longitude - Address2.longitude; double distance = Math.sqrt(Math.pow(la_distance, 2) + Math.pow(lo_distance, 2)); - return distance; + return Math.round(distance * 100000.0) / 100000.0; } } \ No newline at end of file diff --git a/first/restaurant/Food.java b/first/restaurant/Food.java index 8281a04..90cfe2a 100644 --- a/first/restaurant/Food.java +++ b/first/restaurant/Food.java @@ -2,7 +2,7 @@ public class Food { - private Vector menu = new Vector<>(); + private static Vector menu = new Vector<>(); private final String name; private final int price; diff --git a/first/restaurant/Item.java b/first/restaurant/Item.java index 34e92f3..aa5db83 100644 --- a/first/restaurant/Item.java +++ b/first/restaurant/Item.java @@ -10,6 +10,13 @@ public Item(Food food, int count, String description) { this.description = description; } + public Item(Food food, int count) { + this.food = food; + this.count = count; + // empty + this.description = "-"; + } + public Food getFood() { return food; } diff --git a/first/restaurant/Main.java b/first/restaurant/Main.java index e69de29..b5607a7 100644 --- a/first/restaurant/Main.java +++ b/first/restaurant/Main.java @@ -0,0 +1,51 @@ +public static void main(String[] args) { + Address a1 = new Address(2, 3, "Lahijan"); + Address a2 = new Address(5, 6, "Tehran"); + + System.out.println("\n--------------------------------------\n"); + System.out.println("Distance From Address a1 to a2 is: " + a1.distanceFrom(a2)); + System.out.println("\n--------------------------------------\n"); + + Customer c1 = new Customer("MAMAD", a1); + Customer c2 = new Customer("ALI", a2); + + System.out.println("First Customer's ID: " + c1.getCustomerNumber()); + System.out.println("Second Customer's ID: " + c2.getCustomerNumber()); + + Food f1 = new Food("BURGER", 130); + Food f2 = new Food("PIZZA", 200); + Food f3 = new Food("PASTA", 110); + + System.out.println("\n--------------------------------------\n"); + + for (int i = 0; i < Food.getMenu().size(); i++) { + System.out.println("Food Name: " + Food.getMenu().get(i).getName()); + } + + System.out.println("\n--------------------------------------\n"); + + Item it1 = new Item(f1, 2); + Item it2 = new Item(f2, 3, "MORE SAUCE"); + Item it3 = new Item(f3, 1); + + Invoice inv = new Invoice(c1); + + if (inv.addItem(it1) && inv.addItem(it2)) System.out.println("Items added successfully"); + else System.out.println("Items could not be added"); + + if (inv.removeItem(it3)) System.out.println("Item removed successfully"); + else System.out.println("Failed to remove item (item doesn't exist in invoice)"); + + inv.nextStage(); + + System.out.println("Current state: " + inv.getState()); + + System.out.println("\n--------------------------------------\n"); + + for (int i = 0; i < inv.getItems().size(); i++) { + Item it = inv.getItems().get(i); + System.out.println("Food Name: " + it.getFood().getName() + " | Food Description: " + it.getDescription()); + } + + System.out.println("Total price: " + inv.getTotalPrice()); +} \ No newline at end of file