Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZZZ #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

ZZZ #14

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions Drink.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import java.util.Scanner;

public class Drink {
String drinkName;
int price;
int temperature;

Drink() {}

Drink(String drinkName, int price, int temperature) {
this.drinkName = drinkName;
this.price = price;
this.temperature = temperature;
}

Payment payment = new Payment();

void drink() {
Payment payment = new Payment();

showDrinkList();

if (selectDrinkTemperature() == 1) {
showColdDrinkList();
payment.showPayment();

}

else if (selectDrinkTemperature() == 1) {}

}

int userSelectNumber() {
Scanner sc = new Scanner(System.in);
int userSelect = sc.nextInt();
return userSelect;
}


int selectDrinkTemperature() {
int selectNumber = userSelectNumber();
while(true) {
if (selectNumber != 1 || selectNumber != 2) {
Copy link

@huhdy32 huhdy32 Nov 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정이 필요해 보입니다!
selectNumber != 1 && selectNumber != 2 로 바꾸는것이 좋아보이네요 :)

System.out.println("잘못된 입력 입니다.");
}
return setTemperature(selectNumber);
}

}

void showDrinkList() {
System.out.println("음료를 선택해 주세요!");
System.out.println();
System.out.println("[1] 차가운 음료");
System.out.println("[2] 따듯운 음료");
System.out.println();
System.out.print("사용자 입력 > ");
System.out.println();
}

void coldDrink() {
Product product = new Product();

}

void showColdDrinkList() {
Product product = new Product();

System.out.println("[차가운 음료]");
System.out.println();
for(Long i : product.drinkList.keySet()){ //저장된 key값 확인
System.out.println("[" + i + "]" + ": " + product.drinkList.get(i) + "원");
}
System.out.println();
System.out.print("사용자 입력 > ");
System.out.println();
}



void orderDrink() {
Payment payment = new Payment();
System.out.println("[주문 음료]");
System.out.println(drinkName);
System.out.println("[투입 금액]");
System.out.println(payment.cashChange + "원");
System.out.println("[잔돈]");

//if
// System.out.println(payment.cashChange - price + "원 동전 :" + + "개");
}


public int setTemperature(int temperature) {
return this.temperature = temperature;
}


}
27 changes: 27 additions & 0 deletions Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
run();
}

static void run() {
final String HELLO_VENDING_MACHINE = "[어서와요! GDSC 음료 자판기]";
final String ANY_KEY_TO_CONTINUE = "계속 하려면 아무키나 입력하세요 ...";
final String USER_INPUT = "사용자 입력 > ";
final String LINE = "----------------------------";

Scanner sc = new Scanner(System.in);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

축약형 안 쓰면 좋을 것 같아요!

Drink drink = new Drink();

System.out.println(HELLO_VENDING_MACHINE);
System.out.println(ANY_KEY_TO_CONTINUE);
System.out.println(USER_INPUT);
sc.next();
System.out.println(LINE);
System.out.println();

drink.drink();
}
}

68 changes: 68 additions & 0 deletions Payment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import java.util.Scanner;

public class Payment {
String Card;
int cash;
static int cashChange = 0;


int showPayment() {
Scanner sc = new Scanner(System.in);

System.out.println("[결제 방식 선택]");
System.out.println("[1] 현금");
System.out.println("[2] 카드 (부가세 10% 적용)");
System.out.println();
System.out.print("사용자 입력 > ");

int select_Payment_Method = sc.nextInt();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

자바 컨벤션을 따르면

Suggested change
int select_Payment_Method = sc.nextInt();
int paymentMethod = scanner.nextInt();

처럼 될 것 같아요!

System.out.println();
System.out.println("----------------------------");
if(select_Payment_Method != 1 || select_Payment_Method != 2)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 코드를 처음 본 사람은 1이나 2가 무엇을 의미하는 지 바로 알아차리기 어려울 것 같은데요!
매직넘버를 상수화 해도 좋을 것 같네요!

System.out.println("잘못된 입력 입니다.");
return select_Payment_Method;
}

void showCash() {
System.out.println("[현금 투입" + cashChange + "원]");
System.out.println("[1] 5만원권");
System.out.println("[2] 1만원권");
System.out.println("[3] 5천원권");
System.out.println("[4] 1천원권");
System.out.println("[5] 500원");
System.out.println("[6] 100원");
System.out.println("[0] 반환");
System.out.println();
System.out.print("사용자 입력 > ");
//System.out.println("이용해주셔서 감사합니다.");
}

int insertCash() {
Scanner sc = new Scanner(System.in);
int select_Cash = sc.nextInt();
System.out.println("----------------------------");

if (select_Cash == 1)
return 50000;
else if (select_Cash == 2)
return 10000;
else if (select_Cash == 3)
return 5000;
else if (select_Cash == 4)
return 1000;
else if (select_Cash == 5)
return 500;
else if (select_Cash == 6)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기 까지 도달하는 조건은 위의 모든 조건이 false라는 전제 조건을 가지고 있어요.
그렇다면 select_Cash == 6 이라는 조건을 수정하려면 위의 모든 코드들을 살펴봐야 합니다.
빠른 리턴을 해서 줄인다면 더 좋을 것 같아요!

return 100;
return 0;
}

void selectCard() {


}




}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

모든 파일의 끝에는 개행을 추가하는 것이 컨벤션입니다!

20 changes: 20 additions & 0 deletions Product.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import java.util.HashMap;

public class Product {
HashMap<Long, Drink> drinkList = new HashMap<>();

public Product() {
drinkList.put(1L, new Drink("스프라이트", 1500, 1));
drinkList.put(2L, new Drink("코카콜라", 1300, 1));
drinkList.put(3L, new Drink("솔의눈", 1000, 1));
drinkList.put(4L, new Drink("펩시 콜라", 1100, 1));
drinkList.put(5L, new Drink("TOP커피", 2500, 2));
drinkList.put(6L, new Drink("꿀물", 3000, 2));
drinkList.put(7L, new Drink("홍삼차", 3000, 2));
drinkList.put(8L, new Drink("단팥죽", 3000, 2));
}




}