From d3c9e48331bdc745e98abbefc83ebc685f734c24 Mon Sep 17 00:00:00 2001 From: "Amir H. Roosta" <74539567+longkit@users.noreply.github.com> Date: Fri, 3 May 2024 02:08:42 -0700 Subject: [PATCH 1/2] Add files via upload --- Address.java | 39 +++++++++++++++++++++++++++++++++++ Customer.java | 32 +++++++++++++++++++++++++++++ Food.java | 25 ++++++++++++++++++++++ Invoice.java | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ Item.java | 29 ++++++++++++++++++++++++++ 5 files changed, 182 insertions(+) create mode 100644 Address.java create mode 100644 Customer.java create mode 100644 Food.java create mode 100644 Invoice.java create mode 100644 Item.java diff --git a/Address.java b/Address.java new file mode 100644 index 0000000..d870ba0 --- /dev/null +++ b/Address.java @@ -0,0 +1,39 @@ +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 getLatitude() { + return latitude; + } + + public double getLongitude() { + return longitude; + } + + public String getWrittenAddress() { + return written_address; + } + + public double distanceFrom(Address otherAddress) { + double lat1 = (this.latitude); + double lon1 = (this.longitude); + double lat2 = (otherAddress.getLatitude()); + double lon2 = (otherAddress.getLongitude()); + + double dLat = lat2 - lat1; + double dLon = lon2 - lon1; + + double distance = Math.sqrt(Math.pow(dLat, 2) + Math.pow(dLon, 2)); + + + + return distance; + } +} diff --git a/Customer.java b/Customer.java new file mode 100644 index 0000000..f6d23bd --- /dev/null +++ b/Customer.java @@ -0,0 +1,32 @@ +public class Customer { + private static int nextCustomerNumber = 1; + private 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; + } +} diff --git a/Food.java b/Food.java new file mode 100644 index 0000000..7d3195e --- /dev/null +++ b/Food.java @@ -0,0 +1,25 @@ +import java.util.Vector; + +public class Food { + private static Vector menu = new Vector<>(); + private String name; + public 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; + } + + public static Vector getMenu() { + return menu; + } +} diff --git a/Invoice.java b/Invoice.java new file mode 100644 index 0000000..23e362d --- /dev/null +++ b/Invoice.java @@ -0,0 +1,57 @@ +import java.util.Vector; + +class Invoice { + private static final float tax_rate = 9.4f; + private int state; + private Customer customer; + private Vector items; + + public Invoice(Customer customer) { + this.state = -1; + this.customer = customer; + this.items = new Vector<>(); + } + + public int getState() { + return state; + } + + public Customer getCustomer() { + return customer; + } + + public boolean addItem(Item item) { + if (state != -1) + return false; + + items.add(item); + return true; + } + + public boolean removeItem(Item item) { + if (state != -1) + return false; + + return items.remove(item); + } + + public void nextStage() { + state++; + } + + public Vector getItems() { + return items; + } + + public int getTotalPrice() { + int totalPrice = 0; + for (Item item : items) { + totalPrice += item.getFood().getPrice() * item.getCount(); + } + + float taxAmount = (totalPrice * tax_rate) / 100; + + int totalPriceWithTax = Math.round(totalPrice + taxAmount); + return totalPriceWithTax; + } +} diff --git a/Item.java b/Item.java new file mode 100644 index 0000000..eb98c6e --- /dev/null +++ b/Item.java @@ -0,0 +1,29 @@ +class Item { + private Food food; + private int count; + private String description; + + public Item(Food food, int count, String description) { + this.food = food; + this.count = count; + if (description == null) { + this.description = "-"; + } else { + this.description = description; + } + } + + public Food getFood() { + return food; + } + + public int getCount() { + return count; + } + + public String getDescription() { + return description; + } + + +} From 9057af1ea6e303cff6d87cf8655dba25c85bcdea Mon Sep 17 00:00:00 2001 From: "Amir H. Roosta" <74539567+longkit@users.noreply.github.com> Date: Fri, 3 May 2024 02:11:09 -0700 Subject: [PATCH 2/2] Add files via upload --- Restaurant.java | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ Restaurant.zip | Bin 0 -> 3081 bytes 2 files changed, 53 insertions(+) create mode 100644 Restaurant.java create mode 100644 Restaurant.zip diff --git a/Restaurant.java b/Restaurant.java new file mode 100644 index 0000000..b9cdb35 --- /dev/null +++ b/Restaurant.java @@ -0,0 +1,53 @@ +public class Restaurant{ + 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,null); + Item it2 = new Item(f2, 3, "MORE SAUCE"); + Item it3 = new Item(f3, 1, null); + + 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/Restaurant.zip b/Restaurant.zip new file mode 100644 index 0000000000000000000000000000000000000000..cc2041dbe733a9b29242e307c77dc14414aae861 GIT binary patch literal 3081 zcmZ{m2{cq~AHZjfeX=x`GBhOnE(tH$%0wbFwl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