Skip to content

restaurant #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions first/Address.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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 distance_from(Address other) {
double distance = Math.sqrt(Math.pow(other.latitude - this.latitude, 2) +
Math.pow(other.longitude - this.longitude, 2));
return distance;
}
}
32 changes: 32 additions & 0 deletions first/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
public class Customer {
private static int nextCustomerNumber = 1;
private final 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;
}
}
21 changes: 21 additions & 0 deletions first/Food.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import java.util.Vector;

public class Food {
private static Vector<Food> 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 String getName() {
return name;
}

public int getPrice() {
return price;
}
}
58 changes: 58 additions & 0 deletions first/Invoice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import java.util.ArrayList;

public class Invoice {
private static final float tax_rate = 9.4f;
private static final int ORDER_REGISTERED = -1;
private static final int ORDER_PREPARING = 0;
private static final int ORDER_DISPATCHED = 1;
private static final int ORDER_DELIVERED = 2;

private final Customer customer;
private final ArrayList<Item> items;
private int state;

public Invoice(Customer customer) {
this.customer = customer;
this.items = new ArrayList<>();
this.state = ORDER_REGISTERED;
}

public boolean addItem(Item item) {
if (state != ORDER_REGISTERED || !items.contains(item)) {
return false;
}
items.add(item);
return true;
}

public boolean removeItem(Item item) {
if (items.contains(item)) {
items.remove(item);
return true;
}
return false;
}

public void nextStage() {
if (state < ORDER_DELIVERED) {
state++;
}
}

public int getState() {
return state;
}

public Customer getCustomer() {
return customer;
}

public int getTotalPrice() {
int totalPrice = 0;
for (Item item : items) {
totalPrice += item.getFood().getPrice() * item.getCount();
}
float taxAmount = (totalPrice * tax_rate) / 100;
return (int) Math.ceil(totalPrice + taxAmount);
}
}
23 changes: 23 additions & 0 deletions first/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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;
this.description = description;
}

public Food getFood() {
return food;
}

public int getCount() {
return count;
}

public String getDescription() {
return description;
}
}