»Ë»Ñ Æ÷·³
°³¹ßÀÚÆ÷·³ ÀÔ´Ï´Ù.
  • ºÏ¸¶Å© ¾ÆÀÌÄÜ

java Ãʺ¸ÀÚ private¿¡ ´ëÇؼ­ Áú¹®ÀÌ¿ä2

class FruitSeller
{
private int numOfApple;
private int myMoney;
private final int APPLE_PRICE;

public FruitSeller(int money, int appleNum, int price)
{
myMoney=money;
numOfApple=appleNum;
APPLE_PRICE=price;
}
public int saleApple(int money)
{
int num=money/APPLE_PRICE;
numOfApple-=num;
myMoney+=money;
return num;
}
public void showSaleResult()
{
System.out.println("³²Àº »ç°ú : "+numOfApple);
System.out.println("ÆǸŠ¼öÀÍ : "+myMoney);
}
}
-------------------------------------------------------------
class FruitBuyer
{
private int myMoney;
private int numOfApple;
public FruitBuyer(int money)
{
myMoney=money;
numOfApple=0;
}

public void buyApple(FruitSeller seller, int money)
{
numOfApple+=seller.saleApple(money);
myMoney-=money;
}
public void showBuyResult()
{
System.out.println("ÇöÀç ÀÜ¾× : "+myMoney);
System.out.println("»ç°ú °³¼ö : "+numOfApple);
}
}

-------------------------------------------------------------
class FruitSalesMain5
{
public static void main(String[] args)
{
FruitSeller seller=new FruitSeller(0, 30, 1500);
FruitBuyer buyer = new FruitBuyer(10000);

buyer.buyApple(seller, 4500);
System.out.println("°úÀÏ ÆǸÅÀÚÀÇ ÇöÀç »óȲ");
seller.showSaleResult();
System.out.println("°úÀÏ ±¸¸ÅÀÚÀÇ ÇöÀç »óȲ");
buyer.showBuyResult();
}
}
 
 

À§ÀÇ -------------------------------------------------------------Ç¥½Ã´Â Á¦°¡ Ŭ·¡½ºÇ¥½Ã¶§¹®¿¡ ÀÓÀÇ·Î ±Û¾²¸é¼­ ³ÖÀº°Å¿¡¿ä.
 
 
private ¼±¾ðÀº ±× º¯¼ö°¡ ¼±¾ðµÈ Ŭ·¡½º ¹Û¿¡¼± Á¢±ÙÀ» ¸øÇÑ´Ù°í ¹è¿ü½À´Ï´Ù.
 
±Ùµ¥ FruitSalesMain5Ŭ·¡½º¿¡¼± buyer.Apple(seller, 4500);À» ÅëÇؼ­ FruitBuyerÀÇ º¯¼ö numOfApple°ú FruitSeller Ŭ·¡½ºÀÇ º¯¼öµéÀ» º¯È­½ÃÅ°Àݾƿä?
 
±Ùµ¥ Ã¥¿¡¼± ÀÌ·¸°Ô ÇÏ´Â°Ô ¸Â´Ù°í Çϴµ¥ ÀÌÇØ°¡ Àß ¾ÈµË´Ï´Ù.

0
ÃßõÇϱ⠴ٸ¥ÀÇ°ß 0
|
°øÀ¯¹öÆ°

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 ¿ë°³¸®

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 alan0882
  • ¾Ë¸² ¿å¼³, »óó ÁÙ ¼ö ÀÖ´Â ¾ÇÇÃÀº »ï°¡ÁÖ¼¼¿ä.
©¹æ »çÁø  
¡â ÀÌÀü±Û¡ä ´ÙÀ½±Û ¸ñ·Ïº¸±â