📄 priceandstockmanager.java
字号:
/**
* Stores and manages price and stock level of products
*
* @author John Paul Vergara
* @version 1 August 2006
*/
public class PriceAndStockManager
{
private int appleCount = 80;
private double applePrice = 12.35;
private int orangeCount = 40;
private double orangePrice = 22.50;
private int pomeloCount = 20;
private double pomeloPrice = 18.00;
private Product p1;
private Product p2;
private Product p3;
//inistialze
public PriceAndStockManager(int applecount,int orangecount,int pomelocount,
double appleprice,double orangeprice,double pomeloprice)
{
p1=new Product("apple");
p2=new Product("orange");
p3=new Product("pomeloCount");
p1.setStock(applecount);
p2.setStock(orangecount);
p3.setStock(pomelocount);
p1.setPrice(appleprice);
p2.setPrice(orangeprice);
p3.setPrice(pomeloprice);
appleCount=p1.getStock();
orangeCount=p2.getStock();
pomeloCount =p3.getStock();
applePrice=p1.getPrice();
orangePrice=p2.getPrice();
pomeloPrice =p3.getPrice();
}
public int getStock( String product )
{
if ( product.equalsIgnoreCase( "apples" ) )
return appleCount;
else if ( product.equalsIgnoreCase( "oranges" ) )
return orangeCount;
else //if ( product.equalsIgnoreCase( "pomelos" ) )
return pomeloCount;
}
public double getPrice( String product )
{
if ( product.equalsIgnoreCase( "apples" ) )
return applePrice;
else if ( product.equalsIgnoreCase( "oranges" ) )
return orangePrice;
else //if ( product.equalsIgnoreCase( "pomelos" ) )
return pomeloPrice;
}
public void buy( String product, int qty )
{
if ( product.equalsIgnoreCase( "apples" ) )
appleCount -= qty;
else if ( product.equalsIgnoreCase( "oranges" ) )
orangeCount -= qty;
else if ( product.equalsIgnoreCase( "pomelos" ) )
pomeloCount -= qty;
}
public void printInventoryReport()//print the remain number of the apples/oranges/pomelo
{
System.out.println("the remain of the apples number is: "+appleCount);
System.out.println("the remain of the oranges number is: "+orangeCount);
System.out.println("the remain of the pomelos number is: "+pomeloCount);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -