Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Problem3 {
  3.  
  4. private static double CorrectAnswer;
  5.  
  6. public Problem3(double CorrectAnswer)
  7. {
  8. this.CorrectAnswer = CorrectAnswer; // initialize
  9. }
  10.  
  11. public static void main(String[] args){
  12.  
  13. Scanner myScanner = new Scanner (System.in);
  14. System.out.println("How many questions do you want to answer?");
  15. int NumberofQuestions = myScanner.nextInt(); // get the number of questions from the user
  16. System.out.println("What's the maximum number you want?");
  17. int Maximum = myScanner.nextInt(); // get the maximum variable from the user
  18. System.out.println("What's the minimum number you want?");
  19. int Minimum = myScanner.nextInt(); // get the minimum variable from the user
  20. myScanner.nextLine(); // pick up the enter key
  21.  
  22. // passing variables to MathClass
  23. MathClass myMathClass = new MathClass(Maximum, Minimum);
  24.  
  25. for(int i = 0; i < NumberofQuestions; i++) {
  26. // asking the user the question
  27. String UserAnswer;
  28. myMathClass.RandomOperand();
  29. System.out.println(myMathClass.Question()); // call the Question method from MathClass
  30. // user input
  31. UserAnswer = myScanner.nextLine();
  32.  
  33. System.out.println(Double.parseDouble(UserAnswer));
  34. System.out.println(Math.abs(CorrectAnswer - Double.parseDouble(UserAnswer)));
  35.  
  36. if ((CorrectAnswer - Double.parseDouble(UserAnswer) < .000000001)){
  37. System.out.println(MathClass.CorrectAnswer()); // call the Answer method from MathClass
  38. }
  39. else {
  40. System.out.println(MathClass.IncorrectAnswer());
  41. }
  42. }
  43.  
  44. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement