note

자판기 만들기 본문

자바/연습문제

자판기 만들기

투한 2011. 12. 22. 13:57
package com.coffee3;
import java.util.Scanner;


class CoffeeMachine{
	Scanner sc = new Scanner(System.in);
	protected int coffee =10;
	protected int milk =10;
	protected int sugar =10;
	protected int amount;
	protected int balance;
	protected int input;

	public void Process(){
		if(this.coffee>=5 && this.milk>=3 && this.sugar>=1){
			System.out.print("동전을 입력해주세요");
			input = sc.nextInt();
			int i = input;
			if(i>=300){
				this.coffee = coffee-5;
				this.milk = milk-3;
				this.sugar = sugar-1;
				this.amount = 300+amount;
				balance=i-300;
				System.out.println("맛좋은 커피가 준비되었습니다");
			}
			else
				System.out.println("300원 이상 투입하세요");
		}else{
			System.out.println("재료가 부족합니다");
		}
	}
	public void Print(){
		System.out.print("=-=-=-=-=-=-" +
				"=-=-=-=-=-=-=-=-=-=-=-=-=-=" +
				"-=-=-=-=-=-=-=-=-=-" +
				"-=-=-=-=-=-=-=-="+'\n');
		System.out.print("거스름 돈 : "+balance+"원"+'\t');
		System.out.print("커피 잔량 : "+coffee+'\t');
		System.out.print("프림 잔량 : "+milk+'\t');
		System.out.print("설탕 잔량 : "+sugar+'\t');
		System.out.println("기계 잔액"+amount+'\n');
	}

}


public class Main{
	public static void main(String[] args){
		CoffeeMachine co = new CoffeeMachine();
		co.Process();
		co.Print();
		co.Process();
		co.Print();
		co.Process();
		co.Print();
	}
}



간단히 했습니다