티스토리 뷰

JAVA 160608 자판기 복습

package mypack;


public class MachineUse {


public static void main(String[] args) {

Machine gi = new Machine();

gi.showData();

}


}






package mypack;


import java.util.Scanner;


public class Machine {

private int cupCount;

private int coin;

Scanner co = new Scanner(System.in);


public Machine() {

System.out.println("동전을 입력하세요 : ");

coin = co.nextInt();

if(coin >= 200){

System.out.println("몇 잔을 원하세요 : ");

cupCount = co.nextInt();

}else{

System.out.println("돈이 없어요.");

}

}


public int getCoin(){

return coin;

}

public void setCoin(int coin){

this.coin = coin;

}

public int getCupCount(){

return cupCount;

}

public void setCupCount(int cupCount){

this.cupCount = cupCount;

}

public void showData(){

int a;

CoinIn co = new CoinIn();

a = co.sayong(coin, cupCount);

if(a >= 0){

System.out.println("커피" + cupCount + "잔 잔돈 :" + a);

}else{

System.out.println("돈이 부족해요.");

}

}

}







package mypack;

public class CoinIn {
//private int coin;
private int jandon;
public int sayong(int coin, int jan){
return jandon = coin-(200 * jan);
}
}








'📁 공부정리 > JAVA' 카테고리의 다른 글

JAVA 160808 overload overraid  (0) 2016.06.08
JAVA 160608 Singleton  (0) 2016.06.08
JAVA 160608 overload  (0) 2016.06.08
JAVA 160603-3 class  (0) 2016.06.03
JAVA 160603-2 method overload  (0) 2016.06.03

Recent Comments