사과문제

1536 단어 JavaJava

class FruitSeller
{
int PRICE;
int numOfApples;
int money;

public void initFruitSeller(int PRICE,int numOfApples, int money)
{
	this.PRICE=PRICE;
	this.numOfApples=numOfApples;
	this.money=money;
}
public int sell(int money)
{
	this.money +=money;
	int num= money/PRICE;
	numOfApples -=num;
	return num;
}
public void printCS()
{
	System.out.println("사과 값"+PRICE);
	System.out.println("사과 개수"+numOfApples);
	System.out.println("돈"+money);
}

}
class Buyer
{
int numOfApples;
int money;

public void initBuyer(int money)
{
	numOfApples=0;
	this.money=money;
}
public void buy(FruitSeller seller,int money)
{
	this.money -=money;
	this.numOfApples +=seller.sell(money);
}
public void printCS()
{
	System.out.println("사과 개수"+numOfApples);
	System.out.println("돈"+money);
}

}
class FruitMain
{
public static void main(String[] args)
{
FruitSeller seller1=new FruitSeller();
FruitSeller seller2=new FruitSeller();
seller1.initFruitSeller(2000,50,50000);
seller2.initFruitSeller(1000,100,100000);
Buyer buyer=new Buyer();
buyer.initBuyer(20000);
buyer.buy(seller1,6000);
seller1.printCS();
seller2.printCS();
buyer.printCS();
buyer.buy(seller2,5000);
seller1.printCS();
seller2.printCS();
buyer.printCS();
}
}

좋은 웹페이지 즐겨찾기