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"?>
<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" />
</component>
</project>
\ No newline at end of file
......@@ -2,6 +2,15 @@
<project version="4">
<component name="ChangeListManager">
<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" />
</list>
<ignored path="$PROJECT_DIR$/out/" />
......@@ -19,10 +28,20 @@
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/Shop.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="322">
<caret line="337" column="20" selection-start-line="337" selection-start-column="20" selection-end-line="337" selection-end-column="20" />
<state relative-caret-position="408">
<caret line="57" column="6" selection-start-line="57" selection-start-column="6" selection-end-line="57" selection-end-column="6" />
<folding>
<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>
</state>
</provider>
......@@ -47,7 +66,7 @@
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<component name="ProjectFrameBounds" extendedState="7">
<option name="x" value="-10" />
<option name="y" value="-10" />
<option name="width" value="1065" />
......@@ -59,15 +78,17 @@
</navigator>
<panes>
<pane id="Scope" />
<pane id="PackagesPane" />
<pane id="ProjectPane" />
<pane id="PackagesPane" />
</panes>
</component>
<component name="PropertiesComponent">
<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.proportion" value="0.0" />
<property name="project.structure.side.proportion" value="0.0" />
<property name="settings.editor.selected.configurable" value="preferences.lookFeel" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
......@@ -109,7 +130,7 @@
<servers />
</component>
<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" />
<layout>
<window_info id="Image Layers" order="0" />
......@@ -118,10 +139,10 @@
<window_info id="Capture Tool" order="3" />
<window_info id="Favorites" order="4" side_tool="true" />
<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="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="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
......@@ -129,7 +150,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="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="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
......@@ -143,10 +164,20 @@
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/src/Shop.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="322">
<caret line="337" column="20" selection-start-line="337" selection-start-column="20" selection-end-line="337" selection-end-column="20" />
<state relative-caret-position="408">
<caret line="57" column="6" selection-start-line="57" selection-start-column="6" selection-end-line="57" selection-end-column="6" />
<folding>
<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>
</state>
</provider>
......@@ -212,6 +243,17 @@
</splitter-proportions>
</settings>
</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">
<settings>
<splitter-proportions>
......
import com.sun.org.apache.xpath.internal.operations.Or;
import java.awt.*;
import java.util.Iterator;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.HashMap;
import javax.print.DocFlavor;
import java.util.*;
public class Shop {
......@@ -28,8 +25,34 @@ public class Shop {
public void addGood(Good g){ Goods.add(g);}
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){}
......@@ -48,20 +71,38 @@ static class Repository{
{
this.id = id;
this.capacity = capacity;
this.filledCapacity =0;
}
public HashMap <Good,Integer> getListOfGoodsinRepository()
{ return listOfGoodsinRepository; }
public void removeGood(Good g, int amount)
public void removeGood(Good good, int amount)
{
int remain ;
remain = listOfGoodsinRepository.get(g);
remain -= amount;
if( remain <= 0 )
{ listOfGoodsinRepository.remove(g); }
remain = listOfGoodsinRepository.get(good);
if( (remain - amount) > 0 )
{
listOfGoodsinRepository.replace(good,remain,remain-amount);
filledCapacity = filledCapacity -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() {
return id;
......@@ -205,144 +246,22 @@ static class Repository{
String entering;
Shop MyShop =new Shop();
Scanner scan = new Scanner(System.in) ;
while(true){
entering = scan.nextLine();
if(entering.equals("terminate")) return;
if(entering.equals( "add"))
{
String add = scan.nextLine();
if (add.equals("customer")) {
int id = scan.nextInt();
String name = scan.nextLine();
Customer c = new Customer(name,id);
MyShop.addCustomer(c);
}
if(add.equals("good"))
{
Repository a = new Repository(1,200);
Repository b = new Repository(2,100);
MyShop.Repositorys.add(a);
MyShop.Repositorys.add(b);
Repository arr[] = {a,b};
System.out.println(arr[0].getCapacity());
System.out.println(arr[1].getCapacity());
int id = scan.nextInt();
scan.nextLine();
String name =scan.nextLine();
Good amir = new Good(2,"amir",200);
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