JAVA/3. Control
if~else 자판기2
날아올라↗↗
2015. 12. 20. 16:45
728x90
반응형
- package test.com;
- public class Test03VendingMachine2 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- // 콜라500, 사이다700, 쥬스1000
- final String TITLE = "[자판기 프로그램]"; // 타이틀 ment 초기화
- String line = "=================================="; // 라인설정
- System.out.println(TITLE);
- System.out.println(line);
- System.out.println("금액을 투입하세요");
- int money = 1499;
- System.out.println("투입금액 : " + money + "원");
- String menu = null;
- boolean bool = false;
- int x = 0;
- if (money >= 1000) {
- menu = "1.cola, 2.cider, 3.juice";
- bool = true;
- x = 1;
- } else if (money >= 700) {
- menu = "1.cola, 2.cider";
- bool = true;
- x = 1;
- } else if (money >= 500) {
- menu = "1.cola";
- bool = true;
- x = 1;
- } else {
- menu = "금액부족";
- x = 0;
- }
- System.out.println("음료를 선택하세요 (" + menu + ")");
- //if (menu.equals("금액부족")) {
- //if (x == 0) {
- if (!bool) {
- //투입금액이 최소메뉴 금액보다 작을경우
- System.out.println("금액을 더 넣으세요");
- } else {
- int selectNum = 1;
- String drinkName = null;
- int change = money - 0;
- if (selectNum == 1) {
- drinkName = "콜라";
- change = money - 500;
- } else if (selectNum == 2) {
- drinkName = "사이다";
- change = money - 700;
- } else if (selectNum == 3) {
- drinkName = "쥬스";
- change = money - 1000;
- } else {
- drinkName = "잘못선택";
- change = money - 0;
- }
- System.out.println("선택한 음료는 " + drinkName + "");
- System.out.println("잔액 : " + change + "원");
- }
- System.out.println("[종료]");
- }
- }
728x90
반응형