Commit e4b85bb3 authored by amirhasan's avatar amirhasan

corrected

parent a086d581
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_10" default="true" project-jdk-name="10.0.2+13" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>
\ No newline at end of file
...@@ -2,6 +2,15 @@ ...@@ -2,6 +2,15 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="67bfc981-7b10-4bf4-963c-b8f3544bb91a" name="Default Changelist" comment=""> <list default="true" id="67bfc981-7b10-4bf4-963c-b8f3544bb91a" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/untitled/Shop$1.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/untitled/Shop$Customer.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/untitled/Shop$Discount.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/untitled/Shop$Good.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/untitled/Shop$Order.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/untitled/Shop$Repository.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/untitled/Shop.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/Shop.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Shop.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/Shop.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Shop.java" afterDir="false" />
</list> </list>
<ignored path="$PROJECT_DIR$/out/" /> <ignored path="$PROJECT_DIR$/out/" />
...@@ -19,10 +28,18 @@ ...@@ -19,10 +28,18 @@
<file pinned="false" current-in-tab="true"> <file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/Shop.java"> <entry file="file://$PROJECT_DIR$/src/Shop.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="322"> <state relative-caret-position="653">
<caret line="337" column="20" selection-start-line="337" selection-start-column="20" selection-end-line="337" selection-end-column="20" /> <caret line="388" column="5" lean-forward="true" selection-start-line="388" selection-start-column="5" selection-end-line="388" selection-end-column="5" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
<element signature="e#163#173#0" expanded="true" />
<element signature="e#319#325#0" expanded="true" />
<element signature="e#380#387#0" expanded="true" />
<element signature="method#increamentGood#0;class#Shop#0" />
<element signature="e#3278#3279#0" expanded="true" />
<element signature="e#3360#3361#0" expanded="true" />
<element signature="class#Customer#0;class#Repository#0;class#Shop#0" />
<element signature="class#Order#0;class#Repository#0;class#Shop#0" />
</folding> </folding>
</state> </state>
</provider> </provider>
...@@ -59,12 +76,13 @@ ...@@ -59,12 +76,13 @@
</navigator> </navigator>
<panes> <panes>
<pane id="Scope" /> <pane id="Scope" />
<pane id="PackagesPane" />
<pane id="ProjectPane" /> <pane id="ProjectPane" />
<pane id="PackagesPane" />
</panes> </panes>
</component> </component>
<component name="PropertiesComponent"> <component name="PropertiesComponent">
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" /> <property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1555002746370" />
<property name="project.structure.last.edited" value="Modules" /> <property name="project.structure.last.edited" value="Modules" />
<property name="project.structure.proportion" value="0.0" /> <property name="project.structure.proportion" value="0.0" />
<property name="project.structure.side.proportion" value="0.0" /> <property name="project.structure.side.proportion" value="0.0" />
...@@ -82,8 +100,8 @@ ...@@ -82,8 +100,8 @@
</option> </option>
</component> </component>
<component name="RunManager"> <component name="RunManager">
<configuration name="Shop" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true"> <configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="Shop" /> <option name="MAIN_CLASS_NAME" value="sun.rmi.rmic.Main" />
<module name="untitled" /> <module name="untitled" />
<method v="2"> <method v="2">
<option name="Make" enabled="true" /> <option name="Make" enabled="true" />
...@@ -91,7 +109,7 @@ ...@@ -91,7 +109,7 @@
</configuration> </configuration>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Application.Shop" /> <item itemvalue="Application.Main" />
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>
...@@ -108,8 +126,17 @@ ...@@ -108,8 +126,17 @@
</task> </task>
<servers /> <servers />
</component> </component>
<component name="TodoView">
<todo-panel id="selected-file">
<is-autoscroll-to-source value="true" />
</todo-panel>
<todo-panel id="all">
<are-packages-shown value="true" />
<is-autoscroll-to-source value="true" />
</todo-panel>
</component>
<component name="ToolWindowManager"> <component name="ToolWindowManager">
<frame x="-7" y="-7" width="1550" height="838" extended-state="6" /> <frame x="0" y="25" width="1920" height="984" extended-state="6" />
<editor active="true" /> <editor active="true" />
<layout> <layout>
<window_info id="Image Layers" order="0" /> <window_info id="Image Layers" order="0" />
...@@ -118,18 +145,18 @@ ...@@ -118,18 +145,18 @@
<window_info id="Capture Tool" order="3" /> <window_info id="Capture Tool" order="3" />
<window_info id="Favorites" order="4" side_tool="true" /> <window_info id="Favorites" order="4" side_tool="true" />
<window_info id="Structure" order="5" side_tool="true" weight="0.25" /> <window_info id="Structure" order="5" side_tool="true" weight="0.25" />
<window_info content_ui="combo" id="Project" order="6" visible="true" weight="0.023489933" /> <window_info active="true" content_ui="combo" id="Project" order="6" visible="true" weight="0.02347919" />
<window_info anchor="bottom" id="Message" order="0" /> <window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" weight="0.3286119" /> <window_info anchor="bottom" id="Find" order="1" weight="0.3286119" />
<window_info anchor="bottom" id="Run" order="2" weight="0.28045326" /> <window_info anchor="bottom" id="Run" order="2" weight="0.28045326" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" /> <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="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" /> <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" /> <window_info anchor="bottom" id="TODO" order="6" weight="0.32905483" />
<window_info anchor="bottom" id="Terminal" order="7" /> <window_info anchor="bottom" id="Terminal" order="7" />
<window_info anchor="bottom" id="Event Log" order="8" side_tool="true" /> <window_info anchor="bottom" id="Event Log" order="8" side_tool="true" />
<window_info anchor="bottom" id="Version Control" order="9" /> <window_info anchor="bottom" id="Version Control" order="9" />
<window_info anchor="bottom" id="Messages" order="10" /> <window_info anchor="bottom" id="Messages" order="10" weight="0.32982457" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" /> <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" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" /> <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
...@@ -143,10 +170,18 @@ ...@@ -143,10 +170,18 @@
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/src/Shop.java"> <entry file="file://$PROJECT_DIR$/src/Shop.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="322"> <state relative-caret-position="653">
<caret line="337" column="20" selection-start-line="337" selection-start-column="20" selection-end-line="337" selection-end-column="20" /> <caret line="388" column="5" lean-forward="true" selection-start-line="388" selection-start-column="5" selection-end-line="388" selection-end-column="5" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
<element signature="e#163#173#0" expanded="true" />
<element signature="e#319#325#0" expanded="true" />
<element signature="e#380#387#0" expanded="true" />
<element signature="method#increamentGood#0;class#Shop#0" />
<element signature="e#3278#3279#0" expanded="true" />
<element signature="e#3360#3361#0" expanded="true" />
<element signature="class#Customer#0;class#Repository#0;class#Shop#0" />
<element signature="class#Order#0;class#Repository#0;class#Shop#0" />
</folding> </folding>
</state> </state>
</provider> </provider>
......
import com.sun.org.apache.xpath.internal.operations.Or;
import java.awt.*;
import java.util.Iterator; import javax.print.DocFlavor;
import java.util.Scanner; import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
public class Shop { public class Shop {
...@@ -28,8 +25,35 @@ public class Shop { ...@@ -28,8 +25,35 @@ public class Shop {
public void addGood(Good g){ Goods.add(g);} public void addGood(Good g){ Goods.add(g);}
public void increamentGood(Good good, int amount) public void increamentGood(Good good, int amount)
{ {
// todo increament ro adan benevisam
int d= Repositorys.size();
Goods.add(good);
Repository arr [ ] = new Repository[d];
for (int i = 0; i < d; i++) {
arr[i] = Repositorys.get(i);
}
Arrays.sort(arr,new SortbyFreeCapacity());
for (Repository repository: arr) {
if (repository.getFreeCapacity()> amount)
{
repository.addGood(good,amount);
break;
}
}
}
static class SortbyFreeCapacity implements Comparator<Repository>
{
// Used for sorting in ascending order of
// roll number
public int compare(Repository a, Repository b)
{
return a.getFreeCapacity()- b.getFreeCapacity();
}
} }
// public void addDiscount(Discount d, Customer c){} // public void addDiscount(Discount d, Customer c){}
...@@ -48,20 +72,37 @@ static class Repository{ ...@@ -48,20 +72,37 @@ static class Repository{
{ {
this.id = id; this.id = id;
this.capacity = capacity; this.capacity = capacity;
this.filledCapacity =0;
} }
public HashMap <Good,Integer> getListOfGoodsinRepository() public HashMap <Good,Integer> getListOfGoodsinRepository()
{ return listOfGoodsinRepository; } { return listOfGoodsinRepository; }
public void removeGood(Good g, int amount) public void removeGood(Good good, int amount)
{ {
int remain ; int remain ;
remain = listOfGoodsinRepository.get(g); remain = listOfGoodsinRepository.get(good);
remain -= amount;
if( remain <= 0 )
{ listOfGoodsinRepository.remove(g); }
if( (remain - amount) > 0 )
{
listOfGoodsinRepository.replace(good,remain,remain-amount);
filledCapacity = filledCapacity -amount;
}
} }
public void addGood( Good good , int amount) public void addGood( Good good , int amount)
{ listOfGoodsinRepository.put(good,amount); } {
if(listOfGoodsinRepository.containsKey(good) )
{
listOfGoodsinRepository.replace(good,listOfGoodsinRepository.get(good),listOfGoodsinRepository.get(good)+amount);
filledCapacity +=amount;
}
else {
listOfGoodsinRepository.put(good,amount);
filledCapacity+= amount;
}
}
public int getId() { public int getId() {
return id; return id;
...@@ -205,118 +246,119 @@ static class Repository{ ...@@ -205,118 +246,119 @@ static class Repository{
String entering; String entering;
Shop MyShop =new Shop(); Shop MyShop =new Shop();
Scanner scan = new Scanner(System.in) ; Scanner scan = new Scanner(System.in) ;
while(true){ while(true){
entering = scan.nextLine(); entering = scan.nextLine();
if(entering.equals("terminate")) return; if(entering.equals("terminate")) return;
if(entering.equals( "add")) if(entering.equals( "add"))
{ {
String add = scan.nextLine(); String add = scan.nextLine();
if (add.equals("customer")) { if (add.equals("customer")) {
int id = scan.nextInt(); int id = scan.nextInt();
String name = scan.nextLine(); String name = scan.nextLine();
Customer c = new Customer(name,id); Customer c = new Customer(name,id);
MyShop.addCustomer(c); MyShop.addCustomer(c);
} }
if(add.equals("good")) if(add.equals("good"))
{ {
int id = scan.nextInt(); int id = scan.nextInt();
scan.nextLine(); scan.nextLine();
String name =scan.nextLine(); String name =scan.nextLine();
int price = scan.nextInt(); int price = scan.nextInt();
int amount = scan.nextInt(); int amount = scan.nextInt();
Good good = new Good(id,name,price); Good good = new Good(id,name,price);
MyShop.addGood(good); MyShop.addGood(good);
MyShop.increamentGood(good,amount); MyShop.increamentGood(good,amount);
} }
if(add.equals("repository")) if(add.equals("repository"))
{ {
int id =scan.nextInt(); int id =scan.nextInt();
int capacity= scan.nextInt(); int capacity= scan.nextInt();
Repository store = new Repository(id,capacity); Repository store = new Repository(id,capacity);
MyShop.addRepository(store); MyShop.addRepository(store);
} }
if(add.equals("order")) if(add.equals("order"))
{ {
int idOfOrder = scan.nextInt(); int idOfOrder = scan.nextInt();
int idOfCustomer = scan.nextInt(); int idOfCustomer = scan.nextInt();
// Order order = new Order(idOfOrder); // Order order = new Order(idOfOrder);
Customer c = null; Customer c = null;
for( Customer customer : MyShop.Customers) for( Customer customer : MyShop.Customers)
if(customer.getID()==idOfCustomer) c =customer; if(customer.getID()==idOfCustomer) c =customer;
Order order = new Order(idOfOrder,c); Order order = new Order(idOfOrder,c);
MyShop.orders.add(order); MyShop.orders.add(order);
} }
if(add.equals("balance")) if(add.equals("balance"))
{
int IdOfCustomer =scan.nextInt();
int balance = scan.nextInt();
Customer c = null;
for(Customer customer : MyShop.Customers)
{ {
if(customer.getID() == IdOfCustomer) int IdOfCustomer =scan.nextInt();
c = customer; int balance = scan.nextInt();
Customer c = null;
for(Customer customer : MyShop.Customers)
{
if(customer.getID() == IdOfCustomer)
c = customer;
}
int OldBalance = c.getBalance();
int NewBalance = OldBalance + balance;
c.setBalance(NewBalance);
} }
int OldBalance = c.getBalance(); if(add.equals("item"))
int NewBalance = OldBalance + balance; {
c.setBalance(NewBalance); int idOfOrder = scan.nextInt();
} int IdOfGood = scan.nextInt();
if(add.equals("item")) int NumberOfGood = scan.nextInt();
{
int idOfOrder = scan.nextInt();
int IdOfGood = scan.nextInt();
int NumberOfGood = scan.nextInt();
for(Order order : MyShop.orders){ for(Order order : MyShop.orders){
if(order.getID() == idOfOrder) if(order.getID() == idOfOrder)
{ {
for (Good good : order.getItems().keySet()) for (Good good : order.getItems().keySet())
{ {
if (good.getId() == IdOfGood) if (good.getId() == IdOfGood)
{ {
int oldNuberOfGood = order.getItems().get(good); int oldNuberOfGood = order.getItems().get(good);
order.getItems().replace(good, oldNuberOfGood ,oldNuberOfGood+NumberOfGood); order.getItems().replace(good, oldNuberOfGood ,oldNuberOfGood+NumberOfGood);
} }
else { else {
order.Items.put(good,NumberOfGood); order.Items.put(good,NumberOfGood);
} }
} }
} }
} }
}} }}
if(entering.equals("report")) if(entering.equals("report"))
{ {
// except customers others are complete; // except customers others are complete;
String report = scan.nextLine(); String report = scan.nextLine();
if( report.equals("repositories")) if( report.equals("repositories"))
{ {
for( Repository repo : MyShop.Repositorys) { for( Repository repo : MyShop.Repositorys) {
System.out.println(repo.id+","+repo.capacity+","+repo.getFreeCapacity()); } System.out.println(repo.id+","+repo.capacity+","+repo.getFreeCapacity()); }
} }
if(report.equals("income")){ if(report.equals("income")){
System.out.println(MyShop.getIncome()); System.out.println(MyShop.getIncome());
} }
if(report.equals("customers"));/* if(report.equals("customers"));/*
//todo about custromers //todo about custromers
{ {
for (Customer customer : MyShop.Customers){ for (Customer customer : MyShop.Customers){
System.out.println(customer.getID()+","+customer.getName()+","+customer.getBalance()+","); System.out.println(customer.getID()+","+customer.getName()+","+customer.getBalance()+",");
}}*/ }}*/
} }
if(entering.equals("submit")) if(entering.equals("submit"))
{ {
String submit = scan.nextLine(); String submit = scan.nextLine();
...@@ -335,12 +377,14 @@ static class Repository{ ...@@ -335,12 +377,14 @@ static class Repository{
{ {
int IdOfOrder = scan.nextInt(); int IdOfOrder = scan.nextInt();
int IdOfPercet = scan.nextInt(); int IdOfPercet = scan.nextInt();
} }
} }
}} }
}
} }
......
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