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; + } + + +} 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 0000000..cc2041d Binary files /dev/null and b/Restaurant.zip differ