Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package game;
- import game.GameHelper;
- public class MultGame {
- private GameHelper helper = new GameHelper();
- private int numProbs;
- private double points;
- public static void main(String[] args) {
- MultGame game = new MultGame();
- game.createGame();
- game.startPlaying();
- }
- private void createGame() {
- System.out.println("Answer multiplication problems! Each correct answer gets you 1 point!");
- String numProbsReader = helper.getUserInput("To begin, type the number of problems you want to solve and hit enter.");
- numProbs=(Integer.parseInt(numProbsReader));
- }
- private void startPlaying() {
- for(int n=0; n < numProbs; n++){
- int num1=(int)(Math.random()*100);
- int num2=(int)(Math.random()*100);
- int expected = num1*num2;
- System.out.println(" "+num1);
- System.out.println("x"+num2);
- System.out.println("----");
- String userGuess = helper.getUserInput("");
- int guessInt = Integer.parseInt(userGuess);
- if(guessInt==expected){
- this.points++;
- System.out.println("Correct! Total Points: " + points + ". Problems Remaining: " + (numProbs - n - 1));
- }
- else{
- System.out.println("Incorrect! The right answer was " + expected + ":( Total Points: " + points + ". Problems Remaining: " + (numProbs - n - 1));
- }
- }
- endGame();
- }
- private void endGame() {
- System.out.println("Game over! You've guessed all the problems!");
- System.out.println("Your total score was " + points + " ("+((points/numProbs)*100) +"%)!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement