diff --git a/first/Restaurant/Address.java b/first/Restaurant/Address.java new file mode 100644 index 0000000..18e52b2 --- /dev/null +++ b/first/Restaurant/Address.java @@ -0,0 +1,31 @@ +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 = written_Address; + } + public double getLatitude() { + return latitude; + } + public double getLongitude() { + return longitude; + } + public String getWrittenAddress() { + return written_Address; + } + public double distanceFrom(Address anotherAddress) { + double la1 = this.latitude; + double lo1 = this.longitude; + double la2 = anotherAddress.getLatitude(); + double lo2 = anotherAddress.getLongitude(); + + double distance = Math.sqrt(Math.pow(la2 - la1, 2) + Math.pow(lo2 - lo1, 2)); + + + return distance; + } +} \ No newline at end of file diff --git a/first/Restaurant/Customer.java b/first/Restaurant/Customer.java new file mode 100644 index 0000000..8a114c0 --- /dev/null +++ b/first/Restaurant/Customer.java @@ -0,0 +1,28 @@ +public class Customer { + private static int customerCount = 0; + private final int customerNumber; + private String name; + private Address address; + + public Customer(String name, Address address) { + this.name = name; + this.address = address; + this.customerNumber = ++customerCount; + } + + 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; + } +} \ No newline at end of file diff --git a/first/Restaurant/Food.java b/first/Restaurant/Food.java new file mode 100644 index 0000000..c454370 --- /dev/null +++ b/first/Restaurant/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 static Vector getMenu() { + return menu; + } + public String getName() { + return name; + } + public int getPrice() { + return price; + } + +} \ No newline at end of file diff --git a/first/Restaurant/Invoice.java b/first/Restaurant/Invoice.java new file mode 100644 index 0000000..e17f84a --- /dev/null +++ b/first/Restaurant/Invoice.java @@ -0,0 +1,48 @@ +import java.util.ArrayList; +import java.util.List; +public class Invoice { + private final Customer customer; + private final List items; + private int state; + private static final float TAX_RATE = 9.4f; + public List getItems() { + return items; + } + public Invoice(Customer customer) { + this.customer = customer; + this.items = new ArrayList<>(); + this.state = -1; + } + public boolean addItem(Item item) { + if (state == -1) { + items.add(item); + return true; + } + return false; + } + public boolean removeItem(Item item) { + if (state == -1 && items.contains(item)) { + items.remove(item); + return true; + } + return false; + } + public void nextStage() { + state++; + } + public int getTotalPrice() { + int totalPrice = 0; + for (Item item : items) { + totalPrice += item.getFood().getPrice() * item.getCount(); + } + float tax = totalPrice * TAX_RATE / 100; + return (int) Math.ceil(totalPrice + tax); + } + public Customer getCustomer() { + return customer; + } + public int getState() { + return state; + } +} + diff --git a/first/Restaurant/Item.java b/first/Restaurant/Item.java new file mode 100644 index 0000000..6e0e619 --- /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; + if(description != null) { + this.description = description; + } else { + 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/first/Restaurant/Restaurant.java b/first/Restaurant/Restaurant.java new file mode 100644 index 0000000..78cf8d1 --- /dev/null +++ b/first/Restaurant/Restaurant.java @@ -0,0 +1,55 @@ +public class Restaurant { + public static void main(String[] args) { + + Address address1 = new Address(35.7219, 51.3347, "Tehran, Iran"); + Address address2 = new Address(35.652832, 139.839478, "Tokyo, Japan"); + + Customer customer1 = new Customer("Mahdi", address1); + Customer customer2 = new Customer("Haruto", address1); + + Food food1 = new Food("Tahchin", 15); + Food food2 = new Food("Sushi", 25); + + + Item item1 = new Item(food1, 2, "Extra barberry"); + Item item2 = new Item(food2, 3, "soy sauce"); + + + + Invoice invoice1 = new Invoice(customer1); + invoice1.addItem(item1); + invoice1.addItem(item2); + + + System.out.println("\n--------------------------------------\n"); + System.out.println("Distance From Address address1 to address2 is: " + address1.distanceFrom(address2)); + System.out.println("\n--------------------------------------\n"); + System.out.println("First Customer's ID: " + customer1.getCustomerNumber()); + System.out.println("Second Customer's ID: " + customer2.getCustomerNumber()); + 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"); + if (invoice1.addItem(item1) && invoice1.addItem(item2)) System.out.println("Items added successfully"); + else System.out.println("Items could not be added"); + + + invoice1.nextStage(); + + System.out.println("Current state: " + invoice1.getState()); + + System.out.println("\n--------------------------------------\n"); + + for (int i = 0; i < invoice1.getItems().size(); i++) { + Item items = invoice1.getItems().get(i); + System.out.println("Food Name: " + items.getFood().getName() + " | Food Description: " + items.getDescription()); + } + System.out.println("Total price: " + invoice1.getTotalPrice()); + } + +} + +