From 4d74660e4be14dfd15d333ce44c301999fcd1844 Mon Sep 17 00:00:00 2001 From: parnianAghili <168179614+parnianAghili@users.noreply.github.com> Date: Sat, 4 May 2024 15:40:40 +0330 Subject: [PATCH 1/5] Add files via upload --- first/Address.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 first/Address.java diff --git a/first/Address.java b/first/Address.java new file mode 100644 index 0000000..a286594 --- /dev/null +++ b/first/Address.java @@ -0,0 +1,17 @@ +public class Address { + private double latitude; + private double longitude; + private String written_address; + + public Address(double latitude, double longitude, String written_address) { + this.latitude = latitude; + this.longitude = longitude; + this.written_address = written_address; + } + + public double distance_from(Address other) { + double distance = Math.sqrt(Math.pow(other.latitude - this.latitude, 2) + + Math.pow(other.longitude - this.longitude, 2)); + return distance; + } +} From 58bb651acadf9e1fcd3e73dad7e86d126176b914 Mon Sep 17 00:00:00 2001 From: parnianAghili <168179614+parnianAghili@users.noreply.github.com> Date: Sat, 4 May 2024 15:43:24 +0330 Subject: [PATCH 2/5] Add files via upload --- first/Customer.java | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 first/Customer.java diff --git a/first/Customer.java b/first/Customer.java new file mode 100644 index 0000000..ba694b8 --- /dev/null +++ b/first/Customer.java @@ -0,0 +1,32 @@ +public class Customer { + private static int nextCustomerNumber = 1; + private final int customerNumber; + private String name; + private Address address; + + public Customer(String name, Address address) { + this.customerNumber = nextCustomerNumber++; + this.name = name; + this.address = address; + } + + public int getCustomerNumber() { + return customerNumber; + } + + 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; + } +} From a0685f097277aa398a941065f5ff6f496479c2c8 Mon Sep 17 00:00:00 2001 From: parnianAghili <168179614+parnianAghili@users.noreply.github.com> Date: Sat, 4 May 2024 15:45:48 +0330 Subject: [PATCH 3/5] Add files via upload --- first/Food.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 first/Food.java diff --git a/first/Food.java b/first/Food.java new file mode 100644 index 0000000..e79cab7 --- /dev/null +++ b/first/Food.java @@ -0,0 +1,21 @@ +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 String getName() { + return name; + } + + public int getPrice() { + return price; + } +} From 7ccc7abfb477b585b3df042f59ebc1288cbe2091 Mon Sep 17 00:00:00 2001 From: parnianAghili <168179614+parnianAghili@users.noreply.github.com> Date: Sat, 4 May 2024 15:47:20 +0330 Subject: [PATCH 4/5] Add files via upload --- first/Item.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 first/Item.java diff --git a/first/Item.java b/first/Item.java new file mode 100644 index 0000000..93215d2 --- /dev/null +++ b/first/Item.java @@ -0,0 +1,23 @@ +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; + } +} From 5c02dc9717f0d122a44e6187b382fb1a0009da5a Mon Sep 17 00:00:00 2001 From: parnianAghili <168179614+parnianAghili@users.noreply.github.com> Date: Sat, 4 May 2024 15:49:00 +0330 Subject: [PATCH 5/5] Add files via upload --- first/Invoice.java | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 first/Invoice.java diff --git a/first/Invoice.java b/first/Invoice.java new file mode 100644 index 0000000..da62edc --- /dev/null +++ b/first/Invoice.java @@ -0,0 +1,58 @@ +import java.util.ArrayList; + +public class Invoice { + private static final float tax_rate = 9.4f; + private static final int ORDER_REGISTERED = -1; + private static final int ORDER_PREPARING = 0; + private static final int ORDER_DISPATCHED = 1; + private static final int ORDER_DELIVERED = 2; + + private final Customer customer; + private final ArrayList items; + private int state; + + public Invoice(Customer customer) { + this.customer = customer; + this.items = new ArrayList<>(); + this.state = ORDER_REGISTERED; + } + + public boolean addItem(Item item) { + if (state != ORDER_REGISTERED || !items.contains(item)) { + return false; + } + items.add(item); + return true; + } + + public boolean removeItem(Item item) { + if (items.contains(item)) { + items.remove(item); + return true; + } + return false; + } + + public void nextStage() { + if (state < ORDER_DELIVERED) { + state++; + } + } + + public int getState() { + return state; + } + + public Customer getCustomer() { + return customer; + } + + public int getTotalPrice() { + int totalPrice = 0; + for (Item item : items) { + totalPrice += item.getFood().getPrice() * item.getCount(); + } + float taxAmount = (totalPrice * tax_rate) / 100; + return (int) Math.ceil(totalPrice + taxAmount); + } +}