Advertisement
Guest User

MultGame

a guest
Oct 28th, 2011
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. package game;
  2.  
  3. import game.GameHelper;
  4.  
  5. public class MultGame {
  6.     private GameHelper helper = new GameHelper();
  7.     private int numProbs;
  8.     private double points;
  9.    
  10.     public static void main(String[] args) {
  11.         MultGame game = new MultGame();
  12.         game.createGame();
  13.         game.startPlaying();
  14.     }
  15.    
  16.     private void createGame() {
  17.         System.out.println("Answer multiplication problems!  Each correct answer gets you 1 point!");
  18.         String numProbsReader = helper.getUserInput("To begin, type the number of problems you want to solve and hit enter.");
  19.         numProbs=(Integer.parseInt(numProbsReader));
  20.     }
  21.  
  22.    
  23.     private void startPlaying() {
  24.         for(int n=0; n < numProbs; n++){
  25.             int num1=(int)(Math.random()*100);
  26.             int num2=(int)(Math.random()*100);
  27.             int expected = num1*num2;
  28.             System.out.println(" "+num1);
  29.             System.out.println("x"+num2);
  30.             System.out.println("----");
  31.             String userGuess = helper.getUserInput("");
  32.             int guessInt = Integer.parseInt(userGuess);
  33.             if(guessInt==expected){
  34.                 this.points++;
  35.                 System.out.println("Correct!  Total Points: " + points + ".  Problems Remaining: " + (numProbs - n - 1));
  36.             }
  37.             else{
  38.                 System.out.println("Incorrect! The right answer was " + expected + ":(  Total Points: " + points + ".  Problems Remaining: " + (numProbs - n - 1));
  39.             }
  40.         }
  41.         endGame();
  42.     }
  43.  
  44.  
  45.     private void endGame() {
  46.         System.out.println("Game over!  You've guessed all the problems!");
  47.         System.out.println("Your total score was " + points + " ("+((points/numProbs)*100) +"%)!");
  48.     }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement