Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- Game game = new Game();
- game.start();
- }
- }
- import java.util.Scanner;
- public class Game {
- Scanner in;
- static int amountOfQuestions = 5;
- private int points;
- private int currentQuestion;
- private String answer;
- public Game() {
- in = new Scanner(System.in);
- setPoints(0);
- setCurrentQuestion(0);
- answer = null;
- }
- public int getCurrentQuestion() {
- return currentQuestion;
- }
- public void setCurrentQuestion(int currentQuestion) {
- this.currentQuestion = currentQuestion;
- }
- public int getPoints() {
- return points;
- }
- public void setPoints(int points) {
- this.points = points;
- }
- public void askQuestion() {
- if(currentQuestion == 0) {
- do {
- System.out.println("Is milk white? ");
- answer = in.nextLine();
- } while(!(this.answer.equalsIgnoreCase("yes") || this.answer.equalsIgnoreCase("no")));
- if(answer.equalsIgnoreCase("yes"))
- points++;
- currentQuestion++;
- } else if(currentQuestion == 1) {
- do {
- System.out.println("Is milk green? ");
- answer = in.nextLine();
- } while(!(this.answer.equalsIgnoreCase("yes") || this.answer.equalsIgnoreCase("no")));
- if(answer.equalsIgnoreCase("no"))
- points++;
- currentQuestion++;
- } else if(currentQuestion == 2) {
- do {
- System.out.println("Is iphone uses an OS called IOS? ");
- answer = in.nextLine();
- } while(!(this.answer.equalsIgnoreCase("yes") || this.answer.equalsIgnoreCase("no")));
- if(answer.equalsIgnoreCase("yes"))
- points++;
- currentQuestion++;
- } else if(currentQuestion == 3) {
- do {
- System.out.println("Is steve jobs dead? ");
- answer = in.nextLine();
- } while(!(this.answer.equalsIgnoreCase("yes") || this.answer.equalsIgnoreCase("no")));
- if(answer.equalsIgnoreCase("yes"))
- points++;
- currentQuestion++;
- } else if(currentQuestion == 4) {
- do {
- System.out.println("Is galaxy s11 out yet? ");
- answer = in.nextLine();
- } while(!(this.answer.equalsIgnoreCase("yes") || this.answer.equalsIgnoreCase("no")));
- if(answer.equalsIgnoreCase("no"))
- points++;
- currentQuestion++;
- }
- if(currentQuestion == amountOfQuestions) {
- System.out.println("Game ended. Points: " + points);
- }
- }
- public void start() {
- do {
- askQuestion();
- } while(currentQuestion < amountOfQuestions);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement