From b01a889f876f428a5c8e26cd1b9d664770b70856 Mon Sep 17 00:00:00 2001
From: HD0075 <166931753+HD0075@users.noreply.github.com>
Date: Fri, 3 May 2024 23:31:02 +0330
Subject: [PATCH 1/3] commit message
---
first/Restaurant/.gitignore | 29 +++++++++++
first/Restaurant/.idea/.gitignore | 3 ++
first/Restaurant/.idea/misc.xml | 6 +++
first/Restaurant/.idea/modules.xml | 8 +++
first/Restaurant/.idea/vcs.xml | 6 +++
first/Restaurant/Restaurant.iml | 11 +++++
first/Restaurant/src/Address.java | 31 ++++++++++++
first/Restaurant/src/Customer.java | 28 +++++++++++
first/Restaurant/src/Food.java | 21 ++++++++
first/Restaurant/src/Invoice.java | 48 ++++++++++++++++++
first/Restaurant/src/Item.java | 24 +++++++++
first/Restaurant/src/Restaurant.java | 55 +++++++++++++++++++++
first/untitled/.idea/workspace.xml | 74 ++++++++++++++++++++++++++++
13 files changed, 344 insertions(+)
create mode 100644 first/Restaurant/.gitignore
create mode 100644 first/Restaurant/.idea/.gitignore
create mode 100644 first/Restaurant/.idea/misc.xml
create mode 100644 first/Restaurant/.idea/modules.xml
create mode 100644 first/Restaurant/.idea/vcs.xml
create mode 100644 first/Restaurant/Restaurant.iml
create mode 100644 first/Restaurant/src/Address.java
create mode 100644 first/Restaurant/src/Customer.java
create mode 100644 first/Restaurant/src/Food.java
create mode 100644 first/Restaurant/src/Invoice.java
create mode 100644 first/Restaurant/src/Item.java
create mode 100644 first/Restaurant/src/Restaurant.java
create mode 100644 first/untitled/.idea/workspace.xml
diff --git a/first/Restaurant/.gitignore b/first/Restaurant/.gitignore
new file mode 100644
index 0000000..f68d109
--- /dev/null
+++ b/first/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/first/Restaurant/.idea/.gitignore b/first/Restaurant/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/first/Restaurant/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/first/Restaurant/.idea/misc.xml b/first/Restaurant/.idea/misc.xml
new file mode 100644
index 0000000..6f29fee
--- /dev/null
+++ b/first/Restaurant/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/first/Restaurant/.idea/modules.xml b/first/Restaurant/.idea/modules.xml
new file mode 100644
index 0000000..1703cce
--- /dev/null
+++ b/first/Restaurant/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/first/Restaurant/.idea/vcs.xml b/first/Restaurant/.idea/vcs.xml
new file mode 100644
index 0000000..b2bdec2
--- /dev/null
+++ b/first/Restaurant/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/first/Restaurant/Restaurant.iml b/first/Restaurant/Restaurant.iml
new file mode 100644
index 0000000..c90834f
--- /dev/null
+++ b/first/Restaurant/Restaurant.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/first/Restaurant/src/Address.java b/first/Restaurant/src/Address.java
new file mode 100644
index 0000000..18e52b2
--- /dev/null
+++ b/first/Restaurant/src/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/src/Customer.java b/first/Restaurant/src/Customer.java
new file mode 100644
index 0000000..8a114c0
--- /dev/null
+++ b/first/Restaurant/src/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/src/Food.java b/first/Restaurant/src/Food.java
new file mode 100644
index 0000000..c454370
--- /dev/null
+++ b/first/Restaurant/src/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/src/Invoice.java b/first/Restaurant/src/Invoice.java
new file mode 100644
index 0000000..e17f84a
--- /dev/null
+++ b/first/Restaurant/src/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/src/Item.java b/first/Restaurant/src/Item.java
new file mode 100644
index 0000000..6e0e619
--- /dev/null
+++ b/first/Restaurant/src/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/src/Restaurant.java b/first/Restaurant/src/Restaurant.java
new file mode 100644
index 0000000..78cf8d1
--- /dev/null
+++ b/first/Restaurant/src/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());
+ }
+
+}
+
+
diff --git a/first/untitled/.idea/workspace.xml b/first/untitled/.idea/workspace.xml
new file mode 100644
index 0000000..9ba6c27
--- /dev/null
+++ b/first/untitled/.idea/workspace.xml
@@ -0,0 +1,74 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1714756753462
+
+
+ 1714756753462
+
+
+
+
+
+
+
+ file://$PROJECT_DIR$/src/Restaurant.java
+ 44
+
+
+
+
+
+
\ No newline at end of file
From cfef764bb6eca9c6b75f2cac3da3464a84ea78ff Mon Sep 17 00:00:00 2001
From: HD0075 <166931753+HD0075@users.noreply.github.com>
Date: Fri, 3 May 2024 23:32:10 +0330
Subject: [PATCH 2/3] commit message
---
first/untitled/.idea/workspace.xml | 74 ------------------------------
1 file changed, 74 deletions(-)
delete mode 100644 first/untitled/.idea/workspace.xml
diff --git a/first/untitled/.idea/workspace.xml b/first/untitled/.idea/workspace.xml
deleted file mode 100644
index 9ba6c27..0000000
--- a/first/untitled/.idea/workspace.xml
+++ /dev/null
@@ -1,74 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1714756753462
-
-
- 1714756753462
-
-
-
-
-
-
-
- file://$PROJECT_DIR$/src/Restaurant.java
- 44
-
-
-
-
-
-
\ No newline at end of file
From 8ba2335f62292d22a7503f9fb1c4bbee3886d56d Mon Sep 17 00:00:00 2001
From: HD0075 <166931753+HD0075@users.noreply.github.com>
Date: Fri, 3 May 2024 23:42:51 +0330
Subject: [PATCH 3/3] Add existing file
---
first/Restaurant/.gitignore | 29 ----------------------
first/Restaurant/.idea/.gitignore | 3 ---
first/Restaurant/.idea/misc.xml | 6 -----
first/Restaurant/.idea/modules.xml | 8 ------
first/Restaurant/.idea/vcs.xml | 6 -----
first/Restaurant/{src => }/Address.java | 0
first/Restaurant/{src => }/Customer.java | 0
first/Restaurant/{src => }/Food.java | 0
first/Restaurant/{src => }/Invoice.java | 0
first/Restaurant/{src => }/Item.java | 0
first/Restaurant/Restaurant.iml | 11 --------
first/Restaurant/{src => }/Restaurant.java | 0
12 files changed, 63 deletions(-)
delete mode 100644 first/Restaurant/.gitignore
delete mode 100644 first/Restaurant/.idea/.gitignore
delete mode 100644 first/Restaurant/.idea/misc.xml
delete mode 100644 first/Restaurant/.idea/modules.xml
delete mode 100644 first/Restaurant/.idea/vcs.xml
rename first/Restaurant/{src => }/Address.java (100%)
rename first/Restaurant/{src => }/Customer.java (100%)
rename first/Restaurant/{src => }/Food.java (100%)
rename first/Restaurant/{src => }/Invoice.java (100%)
rename first/Restaurant/{src => }/Item.java (100%)
delete mode 100644 first/Restaurant/Restaurant.iml
rename first/Restaurant/{src => }/Restaurant.java (100%)
diff --git a/first/Restaurant/.gitignore b/first/Restaurant/.gitignore
deleted file mode 100644
index f68d109..0000000
--- a/first/Restaurant/.gitignore
+++ /dev/null
@@ -1,29 +0,0 @@
-### 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/first/Restaurant/.idea/.gitignore b/first/Restaurant/.idea/.gitignore
deleted file mode 100644
index 26d3352..0000000
--- a/first/Restaurant/.idea/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
diff --git a/first/Restaurant/.idea/misc.xml b/first/Restaurant/.idea/misc.xml
deleted file mode 100644
index 6f29fee..0000000
--- a/first/Restaurant/.idea/misc.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/first/Restaurant/.idea/modules.xml b/first/Restaurant/.idea/modules.xml
deleted file mode 100644
index 1703cce..0000000
--- a/first/Restaurant/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/first/Restaurant/.idea/vcs.xml b/first/Restaurant/.idea/vcs.xml
deleted file mode 100644
index b2bdec2..0000000
--- a/first/Restaurant/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/first/Restaurant/src/Address.java b/first/Restaurant/Address.java
similarity index 100%
rename from first/Restaurant/src/Address.java
rename to first/Restaurant/Address.java
diff --git a/first/Restaurant/src/Customer.java b/first/Restaurant/Customer.java
similarity index 100%
rename from first/Restaurant/src/Customer.java
rename to first/Restaurant/Customer.java
diff --git a/first/Restaurant/src/Food.java b/first/Restaurant/Food.java
similarity index 100%
rename from first/Restaurant/src/Food.java
rename to first/Restaurant/Food.java
diff --git a/first/Restaurant/src/Invoice.java b/first/Restaurant/Invoice.java
similarity index 100%
rename from first/Restaurant/src/Invoice.java
rename to first/Restaurant/Invoice.java
diff --git a/first/Restaurant/src/Item.java b/first/Restaurant/Item.java
similarity index 100%
rename from first/Restaurant/src/Item.java
rename to first/Restaurant/Item.java
diff --git a/first/Restaurant/Restaurant.iml b/first/Restaurant/Restaurant.iml
deleted file mode 100644
index c90834f..0000000
--- a/first/Restaurant/Restaurant.iml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/first/Restaurant/src/Restaurant.java b/first/Restaurant/Restaurant.java
similarity index 100%
rename from first/Restaurant/src/Restaurant.java
rename to first/Restaurant/Restaurant.java