Commit 4e2b7308 authored by amirhasan's avatar amirhasan

1

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" afterPath="$PROJECT_DIR$/out/production/untitled/Shop$1.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/untitled/Shop$Customer.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/untitled/Shop$Customer.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/untitled/Shop$Discount.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/untitled/Shop$Discount.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/untitled/Shop$Good.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/untitled/Shop$Good.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/untitled/Shop$Order.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/untitled/Shop$Order.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/untitled/Shop$Repository.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/untitled/Shop$Repository.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/untitled/Shop.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/untitled/Shop.class" afterDir="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,20 @@ ...@@ -19,10 +28,20 @@
<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="408">
<caret line="337" column="20" selection-start-line="337" selection-start-column="20" selection-end-line="337" selection-end-column="20" /> <caret line="57" column="6" selection-start-line="57" selection-start-column="6" selection-end-line="57" selection-end-column="6" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
<element signature="e#1350#1351#0" expanded="true" />
<element signature="e#1413#1414#0" expanded="true" />
<element signature="e#3237#3238#0" expanded="true" />
<element signature="e#3319#3320#0" expanded="true" />
<element signature="class#Good#0;class#Shop#0" />
<element signature="class#Customer#0;class#Shop#0" />
<element signature="class#Order#0;class#Shop#0" />
<element signature="class#Discount#0;class#Shop#0" />
<element signature="method#Discount#0;class#Discount#0;class#Shop#0" />
<element signature="method#setOrder#0;class#Discount#0;class#Shop#0" />
</folding> </folding>
</state> </state>
</provider> </provider>
...@@ -47,7 +66,7 @@ ...@@ -47,7 +66,7 @@
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectFrameBounds" extendedState="6"> <component name="ProjectFrameBounds" extendedState="7">
<option name="x" value="-10" /> <option name="x" value="-10" />
<option name="y" value="-10" /> <option name="y" value="-10" />
<option name="width" value="1065" /> <option name="width" value="1065" />
...@@ -59,15 +78,17 @@ ...@@ -59,15 +78,17 @@
</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="1555000483442" />
<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" />
<property name="settings.editor.selected.configurable" value="preferences.lookFeel" />
</component> </component>
<component name="RunDashboard"> <component name="RunDashboard">
<option name="ruleStates"> <option name="ruleStates">
...@@ -109,7 +130,7 @@ ...@@ -109,7 +130,7 @@
<servers /> <servers />
</component> </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,10 +139,10 @@ ...@@ -118,10 +139,10 @@
<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 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.27953216" />
<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" />
...@@ -129,7 +150,7 @@ ...@@ -129,7 +150,7 @@
<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.32937366" />
<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 +164,20 @@ ...@@ -143,10 +164,20 @@
<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="408">
<caret line="337" column="20" selection-start-line="337" selection-start-column="20" selection-end-line="337" selection-end-column="20" /> <caret line="57" column="6" selection-start-line="57" selection-start-column="6" selection-end-line="57" selection-end-column="6" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
<element signature="e#1350#1351#0" expanded="true" />
<element signature="e#1413#1414#0" expanded="true" />
<element signature="e#3237#3238#0" expanded="true" />
<element signature="e#3319#3320#0" expanded="true" />
<element signature="class#Good#0;class#Shop#0" />
<element signature="class#Customer#0;class#Shop#0" />
<element signature="class#Order#0;class#Shop#0" />
<element signature="class#Discount#0;class#Shop#0" />
<element signature="method#Discount#0;class#Discount#0;class#Shop#0" />
<element signature="method#setOrder#0;class#Discount#0;class#Shop#0" />
</folding> </folding>
</state> </state>
</provider> </provider>
...@@ -212,6 +243,17 @@ ...@@ -212,6 +243,17 @@
</splitter-proportions> </splitter-proportions>
</settings> </settings>
</state> </state>
<state key="ProjectJDKs.UI">
<settings>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="ProjectLibrariesConfigurable.UI"> <state key="ProjectLibrariesConfigurable.UI">
<settings> <settings>
<splitter-proportions> <splitter-proportions>
......
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,34 @@ public class Shop { ...@@ -28,8 +25,34 @@ 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();
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);
}
}
}
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 +71,38 @@ static class Repository{ ...@@ -48,20 +71,38 @@ 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 ) if( (remain - amount) > 0 )
{ listOfGoodsinRepository.remove(g); } {
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,144 +246,22 @@ static class Repository{ ...@@ -205,144 +246,22 @@ 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){ Repository a = new Repository(1,200);
entering = scan.nextLine(); Repository b = new Repository(2,100);
if(entering.equals("terminate")) return; MyShop.Repositorys.add(a);
if(entering.equals( "add")) MyShop.Repositorys.add(b);
{ Repository arr[] = {a,b};
String add = scan.nextLine(); System.out.println(arr[0].getCapacity());
if (add.equals("customer")) { System.out.println(arr[1].getCapacity());
int id = scan.nextInt();
String name = scan.nextLine();
Customer c = new Customer(name,id);
MyShop.addCustomer(c);
}
if(add.equals("good"))
{
int id = scan.nextInt();
scan.nextLine(); Good amir = new Good(2,"amir",200);
String name =scan.nextLine();
int price = scan.nextInt(); MyShop.increamentGood(amir,150);
System.out.println(arr[0].getFreeCapacity());
System.out.println(arr[1].getFreeCapacity());
int amount = scan.nextInt(); }}
Good good = new Good(id,name,price);
MyShop.addGood(good);
MyShop.increamentGood(good,amount);
}
if(add.equals("repository"))
{
int id =scan.nextInt();
int capacity= scan.nextInt();
Repository store = new Repository(id,capacity);
MyShop.addRepository(store);
}
if(add.equals("order"))
{
int idOfOrder = scan.nextInt();
int idOfCustomer = scan.nextInt();
// Order order = new Order(idOfOrder);
Customer c = null;
for( Customer customer : MyShop.Customers)
if(customer.getID()==idOfCustomer) c =customer;
Order order = new Order(idOfOrder,c);
MyShop.orders.add(order);
}
if(add.equals("balance"))
{
int IdOfCustomer =scan.nextInt();
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);
}
if(add.equals("item"))
{
int idOfOrder = scan.nextInt();
int IdOfGood = scan.nextInt();
int NumberOfGood = scan.nextInt();
for(Order order : MyShop.orders){
if(order.getID() == idOfOrder)
{
for (Good good : order.getItems().keySet())
{
if (good.getId() == IdOfGood)
{
int oldNuberOfGood = order.getItems().get(good);
order.getItems().replace(good, oldNuberOfGood ,oldNuberOfGood+NumberOfGood);
}
else {
order.Items.put(good,NumberOfGood);
}
}
}
}
}}
if(entering.equals("report"))
{
// except customers others are complete;
String report = scan.nextLine();
if( report.equals("repositories"))
{
for( Repository repo : MyShop.Repositorys) {
System.out.println(repo.id+","+repo.capacity+","+repo.getFreeCapacity()); }
}
if(report.equals("income")){
System.out.println(MyShop.getIncome());
}
if(report.equals("customers"));/*
//todo about custromers
{
for (Customer customer : MyShop.Customers){
System.out.println(customer.getID()+","+customer.getName()+","+customer.getBalance()+",");
}}*/
}
if(entering.equals("submit"))
{
String submit = scan.nextLine();
if(submit.equals("order"))
{
int IdOfOrder = scan.nextInt();
for( Order order : MyShop.orders)
{
if(order.getID() == IdOfOrder)
order.setStatus("submitted");
}
//todo if we submit we must decrease the repositry
// which repositry to decrease >>??
}
if(submit.equals("discount"))
{
int IdOfOrder = 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