Commit ed52f3f1 authored by amirhasan's avatar amirhasan

bashe

parent 44fb8c9b
......@@ -2,7 +2,6 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="67bfc981-7b10-4bf4-963c-b8f3544bb91a" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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/" />
......@@ -20,16 +19,29 @@
<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="338">
<caret line="395" column="21" lean-forward="true" selection-start-line="395" selection-start-column="21" selection-end-line="395" selection-end-column="21" />
<state relative-caret-position="436">
<caret line="199" column="23" selection-start-line="199" selection-start-column="23" selection-end-line="199" selection-end-column="23" />
<folding>
<element signature="imports" expanded="true" />
<element signature="method#increamentGood#0;class#Shop#0" />
<element signature="e#1004#1005#0" expanded="true" />
<element signature="e#1032#1033#0" expanded="true" />
<element signature="class#SortbyFreeCapacity#0;class#Shop#0" />
<element signature="class#Repository#0;class#Shop#0" />
<element signature="e#2368#2369#0" expanded="true" />
<element signature="e#2422#2423#0" expanded="true" />
<element signature="e#3381#3382#0" expanded="true" />
<element signature="e#3439#3440#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="e#3734#3735#0" expanded="true" />
<element signature="e#3767#3768#0" expanded="true" />
<element signature="e#3800#3801#0" expanded="true" />
<element signature="e#3836#3837#0" expanded="true" />
<element signature="e#3871#3872#0" expanded="true" />
<element signature="e#3906#3907#0" expanded="true" />
<element signature="method#Customer#0;class#Customer#0;class#Shop#0" />
<element signature="e#4742#4743#0" expanded="true" />
<element signature="e#4779#4780#0" expanded="true" />
<element signature="e#5472#5473#0" expanded="true" />
<element signature="e#5516#5517#0" expanded="true" />
<element signature="e#6258#6259#0" expanded="true" />
<element signature="e#6280#6281#0" expanded="true" />
<element signature="e#6310#6311#0" expanded="true" />
......@@ -59,9 +71,8 @@
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="-10" />
<option name="y" value="-10" />
<option name="width" value="1065" />
<option name="y" value="27" />
<option name="width" value="1055" />
<option name="height" value="980" />
</component>
<component name="ProjectView">
......@@ -165,8 +176,8 @@
<window_info content_ui="combo" id="Project" order="6" visible="true" weight="0.09284952" />
<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.27953216" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Run" order="2" weight="0.28070176" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.39766082" />
<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" weight="0.32905483" />
......@@ -190,16 +201,29 @@
</entry>
<entry file="file://$PROJECT_DIR$/src/Shop.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="338">
<caret line="395" column="21" lean-forward="true" selection-start-line="395" selection-start-column="21" selection-end-line="395" selection-end-column="21" />
<state relative-caret-position="436">
<caret line="199" column="23" selection-start-line="199" selection-start-column="23" selection-end-line="199" selection-end-column="23" />
<folding>
<element signature="imports" expanded="true" />
<element signature="method#increamentGood#0;class#Shop#0" />
<element signature="e#1004#1005#0" expanded="true" />
<element signature="e#1032#1033#0" expanded="true" />
<element signature="class#SortbyFreeCapacity#0;class#Shop#0" />
<element signature="class#Repository#0;class#Shop#0" />
<element signature="e#2368#2369#0" expanded="true" />
<element signature="e#2422#2423#0" expanded="true" />
<element signature="e#3381#3382#0" expanded="true" />
<element signature="e#3439#3440#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="e#3734#3735#0" expanded="true" />
<element signature="e#3767#3768#0" expanded="true" />
<element signature="e#3800#3801#0" expanded="true" />
<element signature="e#3836#3837#0" expanded="true" />
<element signature="e#3871#3872#0" expanded="true" />
<element signature="e#3906#3907#0" expanded="true" />
<element signature="method#Customer#0;class#Customer#0;class#Shop#0" />
<element signature="e#4742#4743#0" expanded="true" />
<element signature="e#4779#4780#0" expanded="true" />
<element signature="e#5472#5473#0" expanded="true" />
<element signature="e#5516#5517#0" expanded="true" />
<element signature="e#6258#6259#0" expanded="true" />
<element signature="e#6280#6281#0" expanded="true" />
<element signature="e#6310#6311#0" expanded="true" />
......
import javax.print.DocFlavor;
import java.awt.font.FontRenderContext;
import java.util.*;
public class Shop {
private String nameOfShop;
private ArrayList <Customer> Customers = new ArrayList<Customer> ( );
private ArrayList <Repository> Repositorys = new ArrayList<Repository>();
private ArrayList <Good> Goods = new ArrayList<Good>();
private ArrayList<Order > orders = new ArrayList<Order>();
private static int income =0;
public void addCustomer(Customer C)
{ Customers.add(C); }
public ArrayList<Customer> getCustomers()
{ return Customers; }
public void addRepository(Repository R)
{ Repositorys.add(R);}
public ArrayList<Repository> getRepository()
{ return Repositorys;}
public int getIncome(){return income;}
public void setIncome(int income){this.income = income;}
public void addGood(Good g){ Goods.add(g);}
public void increamentGood(Good good, int amount)
{
int d= Repositorys.size();
Repository arr [ ] = new Repository[d];
private ArrayList<Customer> Customers = new ArrayList<Customer>();
private ArrayList<Repository> Repositorys = new ArrayList<Repository>();
private ArrayList<Good> Goods = new ArrayList<Good>();
private ArrayList<Order> orders = new ArrayList<Order>();
private int income = 0;
private ArrayList<Discount> discounts = new ArrayList<>();
public void addCustomer(Customer C) {
Customers.add(C);
}
public ArrayList<Customer> getCustomers() {
return Customers;
}
public void addRepository(Repository R) {
Repositorys.add(R);
}
public ArrayList<Repository> getRepository() {
return Repositorys;
}
public int getIncome() {
return income;
}
public void setIncome(int income) {
this.income = income;
}
public void addGood(Good g) {
Goods.add(g);
}
public void increamentGood(Good good, int amount) {
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());
}
Arrays.sort(arr, new SortbyFreeCapacity());
for (Repository repository: arr) {
if (repository.getFreeCapacity()> amount)
{
repository.addGood(good,amount);
break;
}
for (Repository repository : arr) {
if (repository.getFreeCapacity() > amount) {
repository.addGood(good, amount);
break;
}
}
}
static class SortbyFreeCapacity implements Comparator<Repository>
{
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 int compare(Repository a, Repository b) {
return a.getFreeCapacity() - b.getFreeCapacity();
}
}
......@@ -60,299 +75,316 @@ public class Shop {
// public HashMap<Good, Integer> getItemsSold(){};
static class Repository{
static class Repository {
private int id;
private int capacity;
private int filledCapacity;
private HashMap < Good , Integer> listOfGoodsinRepository = new HashMap<Good,Integer>();
private HashMap<Good, Integer> listOfGoodsinRepository = new HashMap<Good, Integer>();
private Repository(int id ,int capacity)
{
private Repository(int id, int capacity) {
this.id = id;
this.capacity = capacity;
this.filledCapacity =0;
this.filledCapacity = 0;
}
public HashMap<Good, Integer> getListOfGoodsinRepository() {
return listOfGoodsinRepository;
}
public HashMap <Good,Integer> getListOfGoodsinRepository()
{ return listOfGoodsinRepository; }
public void removeGood(Good good, int amount)
{
int remain ;
public void removeGood(Good good, int amount) {
int remain;
remain = listOfGoodsinRepository.get(good);
if( (remain - amount) > 0 )
{
listOfGoodsinRepository.replace(good,remain,remain-amount);
filledCapacity = filledCapacity -amount;
if ((remain - amount) > 0) {
listOfGoodsinRepository.replace(good, remain, remain - amount);
filledCapacity = filledCapacity - amount;
}
}
public void addGood( Good good , int amount)
{
if(listOfGoodsinRepository.containsKey(good) )
{
listOfGoodsinRepository.replace(good,listOfGoodsinRepository.get(good),listOfGoodsinRepository.get(good)+amount);
public void addGood(Good good, int amount) {
if (listOfGoodsinRepository.containsKey(good)) {
listOfGoodsinRepository.replace(good, listOfGoodsinRepository.get(good), listOfGoodsinRepository.get(good) + amount);
filledCapacity +=amount;
filledCapacity += amount;
} else {
listOfGoodsinRepository.put(good, amount);
filledCapacity += amount;
}
else {
listOfGoodsinRepository.put(good,amount);
filledCapacity+= amount;
}
}
}
public int getId() {
return id;
}
public int getCapacity()
{
public int getCapacity() {
return capacity;
}
public int getFreeCapacity()
{ return (capacity -filledCapacity);}
public int getFreeCapacity() {
return (capacity - filledCapacity);
}
}
static class Good{
private int id;
private int price ;
static class Good {
private int id;
private int price;
private String name;
public Good(int id ,String name, int price)
{
this.id= id;
this.name= name;
this.price =price;
}
public int getId()
{ return id; }
public int getPrice()
{return price;}
public String getName()
{ return name;}
public Good(int id, String name, int price) {
this.id = id;
this.name = name;
this.price = price;
}
public int getId() {
return id;
}
public int getPrice() {
return price;
}
public String getName() {
return name;
}
}
static class Customer{
static class Customer {
private String name;
private int ID;
private int balance;
ArrayList <Order> orders = new ArrayList<Order>();
ArrayList <Order> pendingOrders = new ArrayList<Order>();
public Customer (String name ,int id)
{ this.name = name;
ArrayList<Order> orders = new ArrayList<Order>();
ArrayList<Order> pendingOrders = new ArrayList<Order>();
ArrayList<Discount> discounts = new ArrayList<>();
ArrayList <Order> submittedOrders = new ArrayList<>();
public Customer(String name, int id) {
this.name = name;
this.ID = id;
}
public int getID(){return ID;}
public String getName () {return name;}
public int getBalance(){return balance;}
public void setBalance(int amount)
{
public int getID() {
return ID;
}
public String getName() {
return name;
}
public int getBalance() {
return balance;
}
public void setBalance(int amount) {
balance = amount;
}
public void addorder(Order o)
{
public void addorder(Order o) {
orders.add(o);
}
public ArrayList<Order> getTOtalOrder()
{ return orders; }
public ArrayList<Order> getPendingOrders()
{
return pendingOrders;
public ArrayList<Order> getTOtalOrder() {
return orders;
}
public ArrayList<Order> getPendingOrders() {
return pendingOrders;
}
public ArrayList <Order> getSubmittedOrders (){return submittedOrders;}
public void set
}
static class Order{
private int ID;
static class Order {
private int ID;
private String status;
private Customer c;
HashMap <Good,Integer> Items = new HashMap<Good,Integer>();
private Customer c;
private Discount discount;
HashMap<Good, Integer> Items = new HashMap<Good, Integer>();
public Order(int id , Customer c)
{
public Order(int id, Customer c) {
ID = id;
this.c = c;
this.status = "pending";
}
public int getID()
{
public int getID() {
return ID;
}
public String getStatus()
{
public String getStatus() {
return status;
}
public HashMap<Good,Integer> getItems()
{
public HashMap<Good, Integer> getItems() {
return Items;
}
public void setStatus(String status)
{
this.status = status;}
public void addItem(Good good, int amount)
{
if( Items.containsKey(good)){
public void setStatus(String status) {
this.status = status;
}
public void addItem(Good good, int amount) {
if (Items.containsKey(good)) {
int Oldamount = Items.get(good);
int Newamount = Oldamount + amount;
Items.replace(good, Oldamount, Newamount);
}
else
Items.put(good , amount);
} else
Items.put(good, amount);
}
public void removeItem(Good good)
{
public void removeItem(Good good) {
Iterator<Good> it = Items.keySet().iterator();
while(it.hasNext())
{
while (it.hasNext()) {
Good sample = it.next();
if ( sample.getId() == good.getId() ) it.remove();
if (sample.getId() == good.getId()) it.remove();
}
}
public void addDiscount(Discount discount) {
this.discount = discount;
c.discounts.add(discount);
}
public int getOrderPrice() {
int price = 0;
for (HashMap.Entry<Good, Integer> item: getItems().entrySet()) {
price += item.getKey().price * item.getValue();
}
return price;
}
}
static class Discount{
static class Discount {
//todo to compelete Discount class;
private int id;
private int percent;
public Discount(int id,int percent)
{
this.id = id;
this.percent = percent;
}
public int getId()
{
return id;
}
public int getPercent()
{
return percent;
}
public void setOrder( Order order)
{
private int id;
private int percent;
public Discount(int id, int percent) {
this.id = id;
this.percent = percent;
}
}
public int getId() {
return id;
}
public int getPercent() {
return percent;
}
public void setOrder(Order order) {
}
}
public static void main(String[] args)
{
public static void main(String[] args) {
String entering;
Shop MyShop =new Shop();
Scanner scan = new Scanner(System.in) ;
Shop MyShop = new Shop();
Scanner scan = new Scanner(System.in);
while(true){
while (true) {
entering = scan.nextLine();
if(entering.equals("terminate")) return;
if(entering.equals( "add"))
{
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);
Customer c = new Customer(name, id);
MyShop.addCustomer(c);
}
if(add.equals("good"))
{
if (add.equals("good")) {
int id = scan.nextInt();
scan.nextLine();
String name =scan.nextLine();
String name = scan.nextLine();
int price = scan.nextInt();
int amount = scan.nextInt();
Good good = new Good(id,name,price);
Good good = new Good(id, name, price);
MyShop.addGood(good);
MyShop.increamentGood(good,amount);
MyShop.increamentGood(good, amount);
}
if(add.equals("repository"))
{
int id =scan.nextInt();
int capacity= scan.nextInt();
Repository store = new Repository(id,capacity);
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"))
{
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);
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();
if (add.equals("balance")) {
int IdOfCustomer = scan.nextInt();
int balance = scan.nextInt();
Customer c = null;
for(Customer customer : MyShop.Customers)
{
if(customer.getID() == IdOfCustomer)
for (Customer customer : MyShop.Customers) {
if (customer.getID() == IdOfCustomer)
{
c = customer;
break;}
}
int OldBalance = c.getBalance();
int NewBalance = OldBalance + balance;
c.setBalance(NewBalance);
}
if(add.equals("item"))
{
if (add.equals("item")) {
int idOfOrder = scan.nextInt();
int IdOfGood = scan.nextInt();
int NumberOfGood = scan.nextInt();
Good newgood = null;
for (Good good : MyShop.Goods) if( good.getId() == IdOfGood )
{
newgood = good;
break;
for (Good good : MyShop.Goods)
if (good.getId() == IdOfGood) {
newgood = good;
break;
}
}
for(Order order : MyShop.orders){
for (Order order : MyShop.orders) {
if(order.getID() == idOfOrder)
{
order.addItem(newgood,NumberOfGood);
if (order.getID() == idOfOrder) {
order.addItem(newgood, NumberOfGood);
}
}
}
if( add.equals("discount"))
{
if (add.equals("discount")) {
int IdOfDiscount = scan.nextInt();
int Percent= scan.nextInt();
Discount discount = new Discount(IdOfDiscount,Percent);
int Percent = scan.nextInt();
Discount discount = new Discount(IdOfDiscount, Percent);
MyShop.discounts.add(discount);
}
......@@ -360,60 +392,86 @@ static class Repository{
}
if(entering.equals("report"))
{
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("repositories")) {
for (Repository repo : MyShop.Repositorys) {
System.out.println(repo.id + "," + repo.capacity + "," + repo.getFreeCapacity());
}
}
if(report.equals("income")){
if (report.equals("income")) {
System.out.println(MyShop.getIncome());
}
if(report.equals("customers"));
{
for (Customer customer : MyShop.Customers)
{
int total = customer.getTOtalOrder().size();
int pending = customer.getPendingOrders().size();
int submit = total - pending;
System.out.println(customer.getID()+","+customer.getName()+","+customer.getBalance()+"," + total+","+ submit );
}
}
if(entering.equals("submit"))
{
String submit = scan.nextLine();
if(submit.equals("order"))
if (report.equals("customers")) ;
{
int IdOfOrder = scan.nextInt();
for( Order order : MyShop.orders)
{
if(order.getID() == IdOfOrder)
order.setStatus("submitted");
for (Customer customer : MyShop.Customers) {
int total = customer.getTOtalOrder().size();
int pending = customer.getPendingOrders().size();
int submit = total - pending;
System.out.println(customer.getID() + "," + customer.getName() + "," + customer.getBalance() + "," + total + "," + submit);
}
}
if(submit.equals("discount"))
{
int IdOfOrder = scan.nextInt();
int IdOfPercet = scan.nextInt();
if (entering.equals("submit")) {
String submit = scan.nextLine();
if (submit.equals("order")) {
int IdOfOrder = scan.nextInt();
Order neworder = null;
for (Order order : MyShop.orders) {
if (order.getID() == IdOfOrder) {
neworder = order;
break;
}
}
}
if (submit.equals("discount")) {
int IdOfOrder = scan.nextInt();
int IdOfDiscount = scan.nextInt();
Order neworder = null;
Discount newdiscount = null;
for (Order order : MyShop.orders) {
if (IdOfOrder == order.getID()) {
neworder = order;
break;
}
}
for (Discount discount : MyShop.discounts) {
if (discount.getId() == IdOfDiscount) {
newdiscount = discount;
break;
}
}
if (!neworder.c.discounts.contains(newdiscount))
{
neworder.addDiscount(newdiscount);
}
}
}
}
}
}
}
}
}}
}
}
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