package com.coffeeEx;

import java.util.Scanner;
 
public class CoffeeMachine {
 
       public static final int PRICE = 300;
       public static final int CONTENT_COFFEE = 5;
       public static final int CONTENT_MILK = 3;
       public static final int CONTENT_SUGAR = 1;
 
       private int coffee = 10;
       private int milk = 10;
       private int sugar = 10;
       private int amount;
 
       Scanner br;
 
       public CoffeeMachine(){
             br = new Scanner(System.in);
             proccess();
             print();
       }
 
       public void proccess(){
             while(true){
                    System.out.print("동전을 넣으세요(커피값 " + PRICE+"원): ");
                    if(!isSale(br.nextInt())){
                           break;
                    }
             }
       }
 
       public boolean isSale(int coin){
             if (coin < PRICE){
                    System.out.println("동전이 부족합니다.");
                    return false;
             }
             if (coffee < CONTENT_COFFEE){
                    System.out.println("커피가 부족합니다.");
                    return false;
             }
             if (milk < CONTENT_MILK){
                    System.out.println("프림이  부족합니다.");
                    return false;
             }
             if (sugar < CONTENT_SUGAR){
                    System.out.println("설탕이  부족합니다.");
                    return false;
             }
             processCoffee(coin);
             return true;
       }
      
       public void processCoffee(int coin){
             if(coin > PRICE){
                    System.out.println("거스름: "+ (coin -PRICE));
             }
             //커피차감
             setCoffee(getCoffee() - CONTENT_COFFEE);
             //프림차감
             setMilk(getMilk() - CONTENT_MILK);
             //설탕차감
             setSugar(getSugar() - CONTENT_SUGAR);
             setAmount(getAmount() + PRICE);
      
             System.out.println("맛 좋은 커피가 준비되었습니다.");
       }
 
       public void print(){
             System.out.println("======현재 자판기 정보======");
             System.out.println("커피양 : " + getCoffee());
             System.out.println("프림양 : " + getMilk());
             System.out.println("설탕양 : " + getSugar());
             System.out.println("보유금액 : " + getAmount());
       }           
       public static void main(String[] args){
             new CoffeeMachine();
       }
 
       public int getCoffee(){
             return coffee;
       }
       public void setCoffee(int coffee){
             this.coffee = coffee ;
       }
       public int getMilk(){
             return milk;
       }
       public void setMilk(int milk){
             this.milk = milk ;
       }
       public int getSugar(){
             return sugar;
       }
       public void setSugar(int sugar){
             this.sugar = sugar ;
       }
       public int getAmount(){
             return amount;
       }
       public void setAmount(int amount){
             this.amount = amount ;
       }
}


+ Recent posts