Skip to content

Commit cdaad29

Browse files
committed
move to restuarant dir
1 parent 17cba68 commit cdaad29

File tree

6 files changed

+104
-1
lines changed

6 files changed

+104
-1
lines changed
File renamed without changes.

Customer.java renamed to restaurant/Customer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class Customer {
66
public Customer(int number, String name, Address address) {
77
this.number = number;
88
this.name = name;
9-
this.address = new Address(latitude, longitude, writtenAddress);
9+
this.address = address;
1010
}
1111

1212
public int getCustomerNumber() {
File renamed without changes.

restaurant/Invoice.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import java.util.Vector;
2+
3+
class Invoice {
4+
private static final float taxRate = 9.4;
5+
private Customer customer;
6+
private boolean acceptingOrder;
7+
private Vector<Item> items;
8+
9+
public Invoice(Customer customer) {
10+
this.customer = customer;
11+
this.acceptingOrder = true;
12+
this.items = new Vector<Item>();
13+
}
14+
15+
public boolean addItem(Item item) {
16+
if (acceptingOrder) {
17+
items.add(item);
18+
}
19+
return acceptingOrder;
20+
}
21+
22+
public boolean removeItem(Item item) {
23+
if (acceptingOrder) {
24+
return items.remove(item);
25+
}
26+
return false;
27+
}
28+
29+
public void nextStage() {
30+
this.acceptingOrder = false
31+
}
32+
33+
public int getState() {
34+
return state;
35+
}
36+
37+
public int getTotalPrice() {
38+
double total = 0;
39+
for (Item item : items) {
40+
total += item.getFood().getPrice() * item.getCount();
41+
}
42+
return (int) (total * (taxRate + 100) / 100);
43+
}
44+
45+
public Customer getCustomer() {
46+
return customer;
47+
}
48+
49+
public Vector<Item> getItems() {
50+
return items;
51+
}
52+
}
File renamed without changes.

restaurant/Main.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
public static void Main(String[] args) {
2+
Address a1 = new Address(2, 3, "Lahijan");
3+
Address a2 = new Address(5, 6, "Tehran");
4+
5+
System.out.println("\n--------------------------------------\n");
6+
System.out.println("Distance From Address a1 to a2 is: " + a1.distanceFrom(a2));
7+
System.out.println("\n--------------------------------------\n");
8+
9+
Customer c1 = new Customer("MAMAD", a1);
10+
Customer c2 = new Customer("ALI", a2);
11+
12+
System.out.println("First Customer's ID: " + c1.getCustomerNumber());
13+
System.out.println("Second Customer's ID: " + c2.getCustomerNumber());
14+
15+
Food f1 = new Food("BURGER", 130);
16+
Food f2 = new Food("PIZZA", 200);
17+
Food f3 = new Food("PASTA", 110);
18+
19+
System.out.println("\n--------------------------------------\n");
20+
21+
for (int i = 0; i < Food.getMenu().size(); i++) {
22+
System.out.println("Food Name: " + Food.getMenu().get(i).getName());
23+
}
24+
25+
System.out.println("\n--------------------------------------\n");
26+
27+
Item it1 = new Item(f1, 2);
28+
Item it2 = new Item(f2, 3, "MORE SAUCE");
29+
Item it3 = new Item(f3, 1);
30+
31+
Invoice inv = new Invoice(c1);
32+
33+
if (inv.addItem(it1) && inv.addItem(it2)) System.out.println("Items added successfully");
34+
else System.out.println("Items could not be added");
35+
36+
if (inv.removeItem(it3)) System.out.println("Item removed successfully");
37+
else System.out.println("Failed to remove item (item doesn't exist in invoice)");
38+
39+
inv.nextStage();
40+
41+
System.out.println("Current state: " + inv.getState());
42+
43+
System.out.println("\n--------------------------------------\n");
44+
45+
for (int i = 0; i < inv.getItems().size(); i++) {
46+
Item it = inv.getItems().get(i);
47+
System.out.println("Food Name: " + it.getFood().getName() + " | Food Description: " + it.getDescription());
48+
}
49+
50+
System.out.println("Total price: " + inv.getTotalPrice());
51+
}

0 commit comments

Comments
 (0)