Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Problem3 {
- private static double CorrectAnswer;
- public Problem3(double CorrectAnswer)
- {
- this.CorrectAnswer = CorrectAnswer; // initialize
- }
- public static void main(String[] args){
- Scanner myScanner = new Scanner (System.in);
- System.out.println("How many questions do you want to answer?");
- int NumberofQuestions = myScanner.nextInt(); // get the number of questions from the user
- System.out.println("What's the maximum number you want?");
- int Maximum = myScanner.nextInt(); // get the maximum variable from the user
- System.out.println("What's the minimum number you want?");
- int Minimum = myScanner.nextInt(); // get the minimum variable from the user
- myScanner.nextLine(); // pick up the enter key
- // passing variables to MathClass
- MathClass myMathClass = new MathClass(Maximum, Minimum);
- for(int i = 0; i < NumberofQuestions; i++) {
- // asking the user the question
- String UserAnswer;
- myMathClass.RandomOperand();
- System.out.println(myMathClass.Question()); // call the Question method from MathClass
- // user input
- UserAnswer = myScanner.nextLine();
- System.out.println(Double.parseDouble(UserAnswer));
- System.out.println(Math.abs(CorrectAnswer - Double.parseDouble(UserAnswer)));
- if ((CorrectAnswer - Double.parseDouble(UserAnswer) < .000000001)){
- System.out.println(MathClass.CorrectAnswer()); // call the Answer method from MathClass
- }
- else {
- System.out.println(MathClass.IncorrectAnswer());
- }
- }
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement