반응형
드디어 첫번째 프로젝트 마지막 스테이지 !
이번 task는 문제를 내고 맞히면 축하한다는 메세지를 틀리면 다시 하라는 메세지를 보내는 코드를 작성하는것이다.
import java.util.Scanner;
class ChatBot {
final static Scanner scanner = new Scanner(System.in); // Do not change this line
public static void main(String[] args) {
greet("Aid", "2018"); // change it as you need
remindName();
guessAge();
count();
test();
end();
}
static void greet(String assistantName, String birthYear) {
System.out.println("Hello! My name is " + assistantName + ".");
System.out.println("I was created in " + birthYear + ".");
System.out.println("Please, remind me your name.");
}
static void remindName() {
String name = scanner.nextLine();
System.out.println("What a great name you have, " + name + "!");
}
static void guessAge() {
System.out.println("Let me guess your age.");
System.out.println("Enter remainders of dividing your age by 3, 5 and 7.");
int rem3 = scanner.nextInt();
int rem5 = scanner.nextInt();
int rem7 = scanner.nextInt();
int age = (rem3 * 70 + rem5 * 21 + rem7 * 15) % 105;
System.out.println("Your age is " + age + "; that's a good time to start programming!");
}
static void count() {
System.out.println("Now I will prove to you that I can count to any number you want.");
int num = scanner.nextInt();
for (int i = 0; i <= num; i++) {
System.out.printf("%d!\n", i);
}
}
static void test() {
System.out.println("Let's test your programming knowledge.");
// write your code here
System.out.println("Why do we use methods?");
System.out.println("1. To repeat a statement multiple times.");
System.out.println("2. To decompose a program into several small subroutines.");
System.out.println("3. To determine the execution time of a program.");
System.out.println("4. To interrupt the execution of a program.");
int choice = scanner.nextInt();
while(choice != 2){
System.out.println("Please, try again");
choice = scanner.nextInt();
}
}
static void end() {
System.out.println("Congratulations, have a nice day!"); // Do not change this text
}
}
오늘 풀었던 부분은 test() function 인데 정답을 맞출 때 까지 while roop 를 돌려주는게 핵심이었다.
static void test() {
System.out.println("Let's test your programming knowledge.");
// write your code here
System.out.println("Why do we use methods?");
System.out.println("1. To repeat a statement multiple times.");
System.out.println("2. To decompose a program into several small subroutines.");
System.out.println("3. To determine the execution time of a program.");
System.out.println("4. To interrupt the execution of a program.");
int choice = scanner.nextInt();
while(choice != 2){
System.out.println("Please, try again");
choice = scanner.nextInt();
}
}
반응형
'Java > JetBrain Project' 카테고리의 다른 글
JetBrain [Easy] Cinema Room Manager - Stage 2 (0) | 2020.12.05 |
---|---|
JetBrain [Easy] Cinema Room Manager - Stage 1 (0) | 2020.12.05 |
JetBrain [Easy] Simply Chatty Bot 만들기 - Stage 4 (0) | 2020.12.02 |
JetBrain [Easy] Simply Chatty Bot 만들기 - Stage 3 (0) | 2020.12.01 |
JetBrain Academy 이용해서 프로젝트 하기 (2) | 2020.11.25 |