Supply

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class ShopSupply {

public static void main(String[] args) {

// prints info about Supplier, but we don't need it really I guess.

//  Supplier supplier = new Supplier ();
//  System.out.println (supplier.toString());

List <ProductSupply> productsupply = new ArrayList <ProductSupply>();

productsupply.add (new ProductSupply (3,"01/11/2014",1000004,1,2438));
productsupply.add (new ProductSupply (2,"31/10/2014",1000003,1,2755));
productsupply.add (new ProductSupply (3,"01/11/2014",1000002,2,755));
productsupply.add (new ProductSupply (1,"31/10/2014",1000001,2,155));
productsupply.add (new ProductSupply (3,"01/11/2014",1000005,1,2838));

// checks function;

//   List<ProductSupply> n = getSupplyDocument(productsupply, 3);
//    for (ProductSupply m: n) {
//     System.out.println (m.toString());
//   }

// checks function;
//    double amountDocument  = getAmountDocument(productsupply,3);
//    System.out.println ( "Total amount: "+ amountDocument + " " +
"UAH");

// sorts the List bu Id of supply documents;

// Comparator <ProductSupply> p = new ProductIdDocumentComp ();
// Collections.sort (productsupply,p);
// for (ProductSupply l: productsupply) {
// System.out.println (l.toString());
// }

// prints a certain supply document;

PrintSupplyDocument(productsupply,3);
}

// returns the total amount of the certain supply document;
public static double getAmountDocument(List<ProductSupply>x, int
idDocument) {

double amountDocument = 0.0;
for (ProductSupply p : x ){
if(p.getIdDocument() == idDocument){
amountDocument += p.getPurchaseAmount();
}
}return amountDocument;
}

// returns the list of goods in one certain supply document;

public static List<ProductSupply>
getSupplyDocument(List<ProductSupply>x, int idDocument) {
List <ProductSupply> n = new ArrayList <ProductSupply>();
for (ProductSupply p : x ){
if(p.getIdDocument() == idDocument){
n.add (p);
}
}return n;
}

// function to print a certain supply document;

public static void PrintSupplyDocument (List<ProductSupply>x, int
idDocument){
List <ProductSupply> n = new ArrayList <ProductSupply>();
double amountDocument = 0.0;
System.out.println ("id product" + "  " + "quantity"+ "      " +
"price"+ "           " + "total sum" );
for (ProductSupply p : x ){
if(p.getIdDocument() == idDocument){
n.add (p);
System.out.println (p.toString());
amountDocument += p.getPurchaseAmount();
}

} System.out.println ( "_________________________________" + "\n"+"Total
amount: "+ amountDocument + " " + "UAH");
}

}

public class Supplier {
private int idSupplier = 1;
private String nameSupplier = "Fokstrot";
private String telSupplier = "(044) 351-33-22";
private String emailSupplier = "info@te.net.ua";
private String bankSupplier = "Vostok";
private int mfobankSupplier = 456345;
private int bankAccountSupplier = 46748690;

public int getIdSupplier() {
return idSupplier;
}
public void setIdSupplier(int idSupplier) {
this.idSupplier = idSupplier;
}
public String getNameSupplier() {
return nameSupplier;
}
public void setNameSupplier(String nameSupplier) {
this.nameSupplier = nameSupplier;
}
public String getTelSupplier() {
return telSupplier;
}
public void setTelSupplier(String telSupplier) {
this.telSupplier = telSupplier;
}
public String getEmailSupplier() {
return emailSupplier;
}
public void setEmailSupplier(String emailSupplier) {
this.emailSupplier = emailSupplier;
}
public String getBankSupplier() {
return bankSupplier;
}
public void setBankSupplier(String bankSupplier) {
this.bankSupplier = bankSupplier;
}
public int getMfobankSupplier() {
return mfobankSupplier;
}
public void setMfobankSupplier(int mfobankSupplier) {
this.mfobankSupplier = mfobankSupplier;
}
public int getBankAccountSupplier() {
return bankAccountSupplier;
}
public void setBankAccountSupplier(int bankAccountSupplier) {
this.bankAccountSupplier = bankAccountSupplier;
}
public String toString(){
return nameSupplier + " " +  "\n" + "phone: " +  telSupplier + "\n" +
"e-mail: " + emailSupplier+"\n";
}

}
import java.util.Comparator;

public class ProductSupply {
private int idDocument ;
private String dateDocument = "31.10.2014";
private int idProduct;
private int quantity;
private double purchasePrice;

public ProductSupply (int idDocument, String dateDocument, int
idProduct, int quantity, double purchasePrice){
this.idDocument = idDocument;
this.dateDocument = dateDocument;
this.idProduct = idProduct;
this.quantity = quantity;
this.purchasePrice = purchasePrice;

}

public int getIdDocument() {
if (idDocument < 1){
return -1;
}
else {
return idDocument;
}
}

public String getDateDocument() {
return dateDocument;
}

public int getIdProduct() {
return idProduct;
}

public int getQuantity() {
return quantity;
}

public double getPurchasePrice() {
return purchasePrice;
}

public double getPurchaseAmount() {
return purchasePrice * quantity;
}

public String toString(){
return  idProduct +  "        " + quantity +  "        " + purchasePrice
+ "  " + "UAH"+ "      " +getPurchaseAmount() +  "  " + "UAH";
}

}
class ProductIdDocumentComp implements Comparator <ProductSupply> {
public int  compare (ProductSupply a,ProductSupply b) {
double x = a.getIdDocument() - b.getIdDocument();
int result = 0;
if (x==0.0) result = 0;
else if (x< 0.0) result = -1;
else result = 1;
return result;
}

}