Created
January 31, 2014 01:57
-
-
Save kyledecot/8725313 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
import java.util.Scanner; | |
public class Project { | |
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
System.out.print("Enter your name: "); | |
String name = input.nextLine(); | |
int number_of_questions = 4; | |
System.out.println("Welcome " + name + "!" + " Please answer the following questions:\n"); | |
int min = 1; | |
int max = 20; | |
int range = (max - min) + 1; | |
// Generate two random numbers that we'll use for the rest of the program... | |
int first = (int)(Math.random() * range) + min; | |
int second = (int)(Math.random() * range) + min; | |
int score = 0; | |
// Addition Question | |
System.out.print(first + " + " + second + " = "); | |
Integer addition_response = input.nextInt(); | |
if (addition_response == (first + second)) { | |
System.out.println("Correct!"); | |
score++; | |
} else { | |
System.out.println("Wrong!"); | |
System.out.println("The correct answer was " + (first + second)); | |
} | |
System.out.println(""); | |
// Multiplication Question | |
System.out.print(first + " * " + second + " = "); | |
Integer multiplication_response = input.nextInt(); | |
if (multiplication_response == (first * second)) { | |
System.out.println("Correct!"); | |
score++; | |
} else { | |
System.out.println("Wrong!"); | |
System.out.println("The correct answer was " + (first * second)); | |
} | |
System.out.println(""); | |
// TODO: Division question... | |
// TODO: Modulus question.... | |
// Finally Print out the score | |
System.out.println("You got " + score + " correct answers"); | |
System.out.println("That's a " + (((double)score/number_of_questions) * 100) + "%!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment