Dec-06-2020, 01:26 PM
Hello,
We have been assigned to do a project that I find quite hard, and I am a bit stuck.
There are 4 questions and I do not know how to do the last two.
The subject is the following :
Let’s build a Food Delivery program for a restaurant!
Here are the first user actions of our program:
As a user, I can add a new meal
As a user, I can list all the meals
As a user, I can add a new customer
As a user, I can list all the customers
WARNINGS
The software is designed for one restaurant only (e.g. we don’t need a Restaurant class).
The software is designed for the restaurant’s staff only, so no need to design a login interface for customers.
Hence,the first components of our software are:
Meals
Customers
1 - Meals
1.1 - Meal class
Our restaurant sells meals, so we need a way to represent what a meal is.
Each meal has an id, a name and a price.
1.2 - Meal repository
Now that we have a class representing our meals, we need a repository to store them.
This repository is initialized with a txt file. It reads/writes the meals from the file and holds them as objects in a dictionary. The behavior we want for the repository is to:
Add a new meal
Get all the meals
Find a specific meal thanks to its id
2 - Customers
2.1 - Customer class
Our restaurant sells to customers, so we need a way to represent what a customer is.
Each customer has an id, a name and an address.
2.2 - Customer repository
Now that we have a model representing our customers, we need a repository to store them.
This repository is initialized with a txtfile path. It reads/writes the customers from the file and holds them as objects in a dictionary. The behavior we want for the repository is to:
Add a new customer
Get all the customers
Find a specific customer thanks to its id
3 - Orders
Create an Order class to manage orders from customers
An order should have an id, a meal_id (which is the is for the meal ordered), and a customer_id (which is the id for the customer who placed the order), and a ‘delivered’ attribute (a boolean to record whether the order has been delivered or not).
Here are the user actions we want to implement:
I can add a new order
I can list all the undelivered orders
I can mark one order as delivered
4 - Manage data
Implement edit and destroy actions for meals and customers
In our app, a user can’t edit or destroy an existing meal or customer.
Implement these additional user actions:
As a user, I can edit an existing meal
As a user, I can destroy an existing meal
As a user, I can edit an existing customer
As a user, I can destroy an existing customer
Here is what I have done for question 2,
Thanks a lot!
We have been assigned to do a project that I find quite hard, and I am a bit stuck.
There are 4 questions and I do not know how to do the last two.
The subject is the following :
Let’s build a Food Delivery program for a restaurant!
Here are the first user actions of our program:
As a user, I can add a new meal
As a user, I can list all the meals
As a user, I can add a new customer
As a user, I can list all the customers
WARNINGS
The software is designed for one restaurant only (e.g. we don’t need a Restaurant class).
The software is designed for the restaurant’s staff only, so no need to design a login interface for customers.
Hence,the first components of our software are:
Meals
Customers
1 - Meals
1.1 - Meal class
Our restaurant sells meals, so we need a way to represent what a meal is.
Each meal has an id, a name and a price.
1.2 - Meal repository
Now that we have a class representing our meals, we need a repository to store them.
This repository is initialized with a txt file. It reads/writes the meals from the file and holds them as objects in a dictionary. The behavior we want for the repository is to:
Add a new meal
Get all the meals
Find a specific meal thanks to its id
2 - Customers
2.1 - Customer class
Our restaurant sells to customers, so we need a way to represent what a customer is.
Each customer has an id, a name and an address.
2.2 - Customer repository
Now that we have a model representing our customers, we need a repository to store them.
This repository is initialized with a txtfile path. It reads/writes the customers from the file and holds them as objects in a dictionary. The behavior we want for the repository is to:
Add a new customer
Get all the customers
Find a specific customer thanks to its id
3 - Orders
Create an Order class to manage orders from customers
An order should have an id, a meal_id (which is the is for the meal ordered), and a customer_id (which is the id for the customer who placed the order), and a ‘delivered’ attribute (a boolean to record whether the order has been delivered or not).
Here are the user actions we want to implement:
I can add a new order
I can list all the undelivered orders
I can mark one order as delivered
4 - Manage data
Implement edit and destroy actions for meals and customers
In our app, a user can’t edit or destroy an existing meal or customer.
Implement these additional user actions:
As a user, I can edit an existing meal
As a user, I can destroy an existing meal
As a user, I can edit an existing customer
As a user, I can destroy an existing customer
Here is what I have done for question 2,
import csv class Customer: def __init__(self, id_customer, name, address): self.id_customer = id_customer self.name = name self.address = address def load_csv(): with open('customers.csv', newline='') as f: reader = csv.reader(f) data = list(reader) customers = [] for customer in data: customers.append(Customer(customer[0],customer[1],customer[2])) return customers def add_customer(id_customer,name,address): customers.append(Customer(id_customer,name,address)) def get_customer_by_id(id_customer): for customer in customers: if(customer.id_customer == id_customer): return customer def display_customers(): for c in customers: print(c.id_customer,c.name,c.address) customers = load_csv() display_customers() add_customer(4,"Test,","Bal") display_customers() print("Customer with id 4 is :", get_customer_by_id(4).name)It would mean a lot if you could help me for questions 3 and 4, I do not really know how to do them.
Thanks a lot!