Commit a428d864 authored by mrsl2000's avatar mrsl2000

the problem is in order class

parents
Pipeline #691 failed with stages
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="11" project-jdk-type="JavaSDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Lab5.iml" filepath="$PROJECT_DIR$/.idea/Lab5.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="a27e1b3f-baec-49c5-aa91-8422e98fc764" name="Default Changelist" comment="" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="DefaultGradleProjectSettings">
<option name="testRunner" value="GRADLE" />
<option name="delegatedBuild" value="true" />
</component>
<component name="FileEditorManager">
<leaf>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/TestFile.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="136">
<caret line="8" column="56" lean-forward="true" selection-start-line="8" selection-start-column="56" selection-end-line="8" selection-end-column="56" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/com/restaurant/Customer.java">
<provider selected="true" editor-type-id="text-editor" />
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/com/restaurant/Food.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-87" />
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/com/restaurant/Order.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="472">
<caret line="43" column="47" selection-start-line="43" selection-start-column="47" selection-end-line="43" selection-end-column="47" />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/com/restaurant/Order.java" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="18" />
<option name="y" value="-12" />
<option name="width" value="1346" />
<option name="height" value="688" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="Lab5" type="b2602c69:ProjectViewProjectNode" />
<item name="Lab5" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="Lab5" type="b2602c69:ProjectViewProjectNode" />
<item name="Lab5" type="462c0819:PsiDirectoryNode" />
<item name="com" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="Lab5" type="b2602c69:ProjectViewProjectNode" />
<item name="Lab5" type="462c0819:PsiDirectoryNode" />
<item name="com" type="462c0819:PsiDirectoryNode" />
<item name="restaurant" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scope" />
<pane id="PackagesPane" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="a27e1b3f-baec-49c5-aa91-8422e98fc764" name="Default Changelist" comment="" />
<created>1559592984780</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1559592984780</updated>
<workItem from="1559593000541" duration="826000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="826000" />
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1382" height="744" extended-state="6" />
<layout>
<window_info id="Image Layers" />
<window_info id="Designer" />
<window_info id="UI Designer" />
<window_info id="Capture Tool" />
<window_info id="Favorites" side_tool="true" />
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.24962178" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="Docker" show_stripe_button="false" />
<window_info anchor="bottom" id="Database Changes" />
<window_info anchor="bottom" id="Version Control" />
<window_info anchor="bottom" id="Terminal" />
<window_info anchor="bottom" id="Event Log" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="right" id="Palette" />
<window_info anchor="right" id="Theme Preview" />
<window_info anchor="right" id="Maven" />
<window_info anchor="right" id="Capture Analysis" />
<window_info anchor="right" id="Palette&#9;" />
<window_info anchor="right" id="Database" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
</layout>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/TestFile.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="136">
<caret line="8" column="56" lean-forward="true" selection-start-line="8" selection-start-column="56" selection-end-line="8" selection-end-column="56" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/com/restaurant/Customer.java">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/com/restaurant/Food.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-87" />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/com/restaurant/Order.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="472">
<caret line="43" column="47" selection-start-line="43" selection-start-column="47" selection-end-line="43" selection-end-column="47" />
</state>
</provider>
</entry>
</component>
</project>
\ No newline at end of file
File added
#Lab 5
```
problem
```
* Hi
* you are great
* the problem is when goli add another food we dont calculate the price of extra food
* my english is great :)
- mr.sadeghian
\ No newline at end of file
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());
}
}
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;
}
}
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;
}
}
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;
}
}
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;
//////////////////// fix the problem ///////////////////////
price = 0;
for (Food food : foods) {
price += food.getPrice();
}
price *= 1.4;
//////////////////////////////////////////////////////////////
temp = null;
}
public Customer getCustomer() {
return customer;
}
}
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();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment