Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.43 KB | None | 0 0
  1. public class Main {
  2.  
  3.     public static void main(String[] args) {
  4.         Game game = new Game();
  5.         game.start();
  6.     }
  7.    
  8. }
  9.  
  10.  
  11. import java.util.Scanner;
  12.  
  13. public class Game {
  14.  
  15.     Scanner in;
  16.    
  17.     static int amountOfQuestions = 5;
  18.    
  19.     private int points;
  20.     private int currentQuestion;
  21.     private String answer;
  22.    
  23.     public Game() {
  24.         in = new Scanner(System.in);
  25.        
  26.         setPoints(0);
  27.         setCurrentQuestion(0);
  28.         answer = null;
  29.     }
  30.  
  31.     public int getCurrentQuestion() {
  32.         return currentQuestion;
  33.     }
  34.  
  35.     public void setCurrentQuestion(int currentQuestion) {
  36.         this.currentQuestion = currentQuestion;
  37.     }
  38.  
  39.     public int getPoints() {
  40.         return points;
  41.     }
  42.  
  43.     public void setPoints(int points) {
  44.         this.points = points;
  45.     }
  46.    
  47.     public void askQuestion() {
  48.         if(currentQuestion == 0) {
  49.             do {
  50.                 System.out.println("Is milk white? ");
  51.                 answer = in.nextLine();
  52.             } while(!(this.answer.equalsIgnoreCase("yes") || this.answer.equalsIgnoreCase("no")));
  53.            
  54.             if(answer.equalsIgnoreCase("yes"))
  55.                 points++;
  56.             currentQuestion++;
  57.         } else if(currentQuestion == 1) {
  58.             do {
  59.                 System.out.println("Is milk green? ");
  60.                 answer = in.nextLine();
  61.             } while(!(this.answer.equalsIgnoreCase("yes") || this.answer.equalsIgnoreCase("no")));
  62.            
  63.             if(answer.equalsIgnoreCase("no"))
  64.                 points++;          
  65.             currentQuestion++;
  66.         } else if(currentQuestion == 2) {
  67.             do {
  68.                 System.out.println("Is iphone uses an OS called IOS? ");
  69.                 answer = in.nextLine();
  70.             } while(!(this.answer.equalsIgnoreCase("yes") || this.answer.equalsIgnoreCase("no")));
  71.            
  72.             if(answer.equalsIgnoreCase("yes"))
  73.                 points++;
  74.             currentQuestion++;
  75.         } else if(currentQuestion == 3) {
  76.             do {
  77.                 System.out.println("Is steve jobs dead? ");
  78.                 answer = in.nextLine();
  79.             } while(!(this.answer.equalsIgnoreCase("yes") || this.answer.equalsIgnoreCase("no")));
  80.            
  81.             if(answer.equalsIgnoreCase("yes"))
  82.                 points++;
  83.             currentQuestion++;
  84.         } else if(currentQuestion == 4) {
  85.             do {
  86.                 System.out.println("Is galaxy s11 out yet? ");
  87.                 answer = in.nextLine();
  88.             } while(!(this.answer.equalsIgnoreCase("yes") || this.answer.equalsIgnoreCase("no")));
  89.            
  90.             if(answer.equalsIgnoreCase("no"))
  91.                 points++;
  92.             currentQuestion++;
  93.         }
  94.        
  95.         if(currentQuestion == amountOfQuestions) {
  96.             System.out.println("Game ended. Points: " + points);
  97.         }
  98.     }
  99.    
  100.     public void start() {
  101.         do {
  102.             askQuestion();
  103.         } while(currentQuestion < amountOfQuestions);
  104.        
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement