소프트웨어/Java
Coffe2Main 클래스 설명
duriepark09
2008. 9. 19. 02:42
/**
* 클래스 : method + attribute(member field)
* 접근 제한자(access modifier) : public
* class 클래스 이름 : class Coffee2Main
* */
public class Coffee2Main {
/**********************************************
* 접근 제한자(access modifier) : public
* static / non-static : static
* return type : int
* 메소드명 : coffee
* 메소드 목표 : 커피 자판기에 돈(money)을 넣었을때
* 커피 몇 잔이 나올 수 있는지 판단
* ********************************************/
public static int coffee(int money){
// block 변수 이므로 초기화
int cups = 0;
if(money > 0){
// 정상적인 돈을 넣었을 경우
cups = money/200;
}else if(money==0){
// 돈을 넣지 않았을 경우
cups = 0;
}else{
// 돈이 모자랄 경우
cups = -1;
}
return cups;
}//coffee
/**********************************************
* 접근 제한자(access modifier) : public
* static / non-static : static
* return type : void
* 메소드명 : printCoffee
* 메소드 목표 : 커피 자판기에 돈(money)을 넣었을때
* 커피가 몇 잔 나오는지를 출력
* ********************************************/
public static void printCoffee(int cups){
//돈을 200원 이상 넣었을 경우
if(cups > 0){
System.out.println("커피"+cups+"잔입니다.");
//System.out.println("커피 %d잔 입니다.",cups);
}else{
// 돈이 모자랄 경우
System.out.println("액수가 모자랍니다.");
}
}//printCoffee
/**********************************************
* 접근 제한자(access modifier) : public
* static / non-static : static
* return type : void
* 메소드명 : main
* 메소드 목표 : 커피 자판기를 실제로 가동해서
* 몇 잔의 커피가 있는지를 확인
* ********************************************/
public static void main(String[] args)
{
int myMoneyA = 800;// 자판기에 넣을 돈
int cupsA = Coffee2Main.coffee(myMoneyA);// 커피 몇 잔?
Coffee2Main.printCoffee(cupsA);// 커피 잔을 확인할 수 있게 출력!!
int myMoneyB = 150; // 자판기에 넣을 돈
int cupsB = coffee(myMoneyB); // 커피 몇 잔?
printCoffee(cupsB); // 커피가 몇 잔 나왔는지 확인할 수 있게 출력!!
}//main
}