Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
lab5_deadline
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
9531304
lab5_deadline
Commits
3f99d65a
Commit
3f99d65a
authored
May 25, 2019
by
9531304
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
complete
parents
Pipeline
#661
failed with stages
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
294 additions
and
0 deletions
+294
-0
TestFile.java
src/TestFile.java
+31
-0
Customer.java
src/com/restaurant/Customer.java
+30
-0
Food.java
src/com/restaurant/Food.java
+45
-0
Ingredient.java
src/com/restaurant/Ingredient.java
+26
-0
Order.java
src/com/restaurant/Order.java
+49
-0
Restaurant.java
src/com/restaurant/Restaurant.java
+113
-0
No files found.
src/TestFile.java
0 → 100644
View file @
3f99d65a
import
com.restaurant.*
;
public
class
TestFile
{
public
static
void
main
(
String
[]
args
)
{
Restaurant
restaurant
=
new
Restaurant
(
"Java AP Lab"
,
3000
);
Ingredient
i1
=
new
Ingredient
(
1
,
"carrot"
,
20
);
Ingredient
i2
=
new
Ingredient
(
2
,
"meat"
,
50
);
Ingredient
i3
=
new
Ingredient
(
3
,
"bread"
,
10
);
Ingredient
i4
=
new
Ingredient
(
4
,
"potato"
,
20
);
Ingredient
i5
=
new
Ingredient
(
4
,
"onion"
,
30
);
Food
f1
=
new
Food
(
1
,
"ab-goosht"
);
f1
.
addIngredient
(
i3
,
2
);
f1
.
addIngredient
(
i1
,
1
);
f1
.
addIngredient
(
i2
,
1
);
f1
.
addIngredient
(
i4
,
1
);
restaurant
.
addFood
(
f1
);
Food
f2
=
new
Food
(
2
,
"kabab"
);
f2
.
addIngredient
(
i2
,
4
);
f2
.
addIngredient
(
i5
,
5
);
restaurant
.
addFood
(
f2
);
Customer
customer
=
new
Customer
(
1
,
"gholi"
);
restaurant
.
addCustomer
(
customer
);
Food
[]
foods
=
new
Food
[]{
f1
,
f1
};
Order
order1
=
new
Order
(
1
,
customer
,
foods
);
order1
.
addFood
(
f1
,
2
);
restaurant
.
prepareOrder
(
order1
);
restaurant
.
acceptPayment
(
customer
);
System
.
out
.
println
(
restaurant
.
getFund
());
System
.
out
.
println
(
restaurant
.
getNumberOfFoodsDelivered
());
}
}
src/com/restaurant/Customer.java
0 → 100644
View file @
3f99d65a
package
com
.
restaurant
;
public
class
Customer
{
private
int
id
;
private
String
name
;
private
Order
order
;
public
Customer
(
int
id
,
String
name
)
{
this
.
id
=
id
;
this
.
name
=
name
;
}
public
Order
getOrder
()
{
return
order
;
}
public
void
setOrder
(
Order
order
)
{
this
.
order
=
order
;
}
public
int
getId
()
{
return
id
;
}
public
String
getName
()
{
return
name
;
}
}
src/com/restaurant/Food.java
0 → 100644
View file @
3f99d65a
package
com
.
restaurant
;
import
java.util.ArrayList
;
public
class
Food
{
private
int
id
;
private
String
name
;
private
int
price
;
private
ArrayList
<
Ingredient
>
ingredients
;
private
ArrayList
<
Integer
>
ingredientsAmount
;
public
Food
(
int
id
,
String
name
)
{
this
.
id
=
id
;
this
.
name
=
name
;
price
=
0
;
ingredients
=
new
ArrayList
<
Ingredient
>();
ingredientsAmount
=
new
ArrayList
<
Integer
>();
}
public
int
getId
()
{
return
id
;
}
public
String
getName
()
{
return
name
;
}
public
int
getPrice
(){
return
price
;
}
public
void
addIngredient
(
Ingredient
ingredient
,
int
amount
)
{
ingredients
.
add
(
ingredient
);
ingredientsAmount
.
add
(
amount
);
price
+=
amount
*
ingredient
.
getPrice
();
}
@Override
public
String
toString
()
{
return
this
.
name
;
}
}
src/com/restaurant/Ingredient.java
0 → 100644
View file @
3f99d65a
package
com
.
restaurant
;
public
class
Ingredient
{
private
int
id
;
private
String
name
;
private
int
price
;
public
Ingredient
(
int
id
,
String
name
,
int
price
)
{
this
.
id
=
id
;
this
.
name
=
name
;
this
.
price
=
price
;
}
public
int
getId
()
{
return
id
;
}
public
String
getName
()
{
return
name
;
}
public
int
getPrice
()
{
return
price
;
}
}
src/com/restaurant/Order.java
0 → 100644
View file @
3f99d65a
package
com
.
restaurant
;
public
class
Order
{
private
int
id
;
private
Customer
customer
;
private
Food
[]
foods
;
private
int
price
;
public
Order
(
int
id
,
Customer
customer
,
Food
[]
foods
)
{
this
.
id
=
id
;
this
.
customer
=
customer
;
this
.
foods
=
foods
;
for
(
Food
food
:
foods
)
{
price
+=
food
.
getPrice
();
}
price
*=
1.4
;
customer
.
setOrder
(
this
);
}
public
Food
[]
getFoods
()
{
return
foods
;
}
public
int
getPrice
()
{
return
price
;
}
public
void
addFood
(
Food
food
,
int
amount
){
Food
[]
temp
=
new
Food
[
foods
.
length
+
amount
];
for
(
int
i
=
0
;
i
<
foods
.
length
;
i
++)
{
temp
[
i
]
=
foods
[
i
];
}
for
(
int
i
=
0
;
i
<
amount
;
i
++)
{
temp
[
foods
.
length
+
i
]
=
food
;
}
foods
=
temp
;
temp
=
null
;
price
=
0
;
for
(
int
j
=
0
;
j
<
foods
.
length
;
j
++){
price
+=
1.4
*
foods
[
j
].
getPrice
();
}
}
public
Customer
getCustomer
()
{
return
customer
;
}
}
src/com/restaurant/Restaurant.java
0 → 100644
View file @
3f99d65a
package
com
.
restaurant
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
public
class
Restaurant
{
private
final
ArrayList
<
Customer
>
currentCustomers
;
private
String
name
;
private
int
fund
;
private
ArrayList
<
Food
>
foods
;
private
ArrayList
<
Customer
>
customers
;
public
Restaurant
(
String
name
,
int
fund
)
{
this
.
name
=
name
;
this
.
fund
=
fund
;
customers
=
new
ArrayList
<>();
currentCustomers
=
new
ArrayList
<>();
this
.
numOrdered
=
new
HashMap
<>();
this
.
foods
=
new
ArrayList
<>();
}
public
HashMap
<
Food
,
Integer
>
numOrdered
=
new
HashMap
<>();
public
Restaurant
(
int
fund
)
{
this
(
"JAVA Coffee house"
,
fund
);
}
public
String
getName
()
{
return
name
;
}
public
int
getFund
()
{
return
fund
;
}
public
ArrayList
<
Food
>
getFoods
()
{
ArrayList
<
Food
>
foodArrayList
=
new
ArrayList
<>();
int
size
=
foods
.
size
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
int
max
=
0
;
Food
chosenFood
=
foods
.
get
(
0
);
for
(
Food
food
:
foods
){
if
(
numOrdered
.
get
(
food
)
>
max
){
chosenFood
=
food
;
max
=
numOrdered
.
get
(
food
);
}
}
foodArrayList
.
add
(
chosenFood
);
foods
.
remove
(
chosenFood
);
}
foods
=
foodArrayList
;
return
foodArrayList
;
}
public
void
addFood
(
Food
food
){
numOrdered
.
put
(
food
,
0
);
foods
.
add
(
food
);
}
public
ArrayList
<
Customer
>
getCustomers
()
{
return
customers
;
}
public
ArrayList
<
Customer
>
getCurrentCustomers
()
{
return
currentCustomers
;
}
public
void
addCustomer
(
Customer
customer
)
{
customers
.
add
(
customer
);
}
public
void
prepareOrder
(
Order
m
)
{
int
cost
=
0
;
for
(
Food
food
:
m
.
getFoods
())
{
int
num
=
numOrdered
.
get
(
food
);
numOrdered
.
put
(
food
,
num
+
1
);
cost
+=
food
.
getPrice
();
}
fund
-=
cost
;
currentCustomers
.
add
(
m
.
getCustomer
());
}
public
void
acceptPayment
(
Customer
customer
)
{
int
menuCost
=
customer
.
getOrder
().
getPrice
();
currentCustomers
.
remove
(
customer
);
fund
+=
menuCost
*
0.9
;
totalNumOfFood
+=
customer
.
getOrder
().
getFoods
().
length
;
}
private
int
totalNumOfFood
=
0
;
public
int
getNumberOfFoodsDelivered
(){
return
totalNumOfFood
;
}
@Override
public
String
toString
()
{
String
toReturn
=
""
;
toReturn
+=
this
.
name
+
"\n"
;
toReturn
+=
this
.
fund
+
"\n"
;
int
totNumSold
=
0
;
for
(
int
num:
numOrdered
.
values
())
{
totNumSold
+=
num
;
}
toReturn
+=
currentCustomers
.
size
()
+
"\n"
;
toReturn
+=
customers
.
size
()
+
"\n"
;
for
(
Food
food:
getFoods
())
toReturn
+=
food
+
"\n"
;
toReturn
+=
totNumSold
+
"\n"
;
return
toReturn
.
trim
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment