Question

So I can not get this to work properly and he does not want us using...

So I can not get this to work properly and he does not want us using an array list. Below is the directions along with the code I have(Im not sure the code is in the right format)  


ITSE 2321 – OBJECT-ORIENTED PROGRAMMING JAVA Program 7 – Methods: A Deeper Look Write a program that will help an elementary school student learn multiplication. Use a SecureRandom object to produce two positive one-digit integers. The program should then prompt the student with a question, such as: How much is 6 times 7? The student then inputs the answer. Next, the program checks the student’s answer. If it’s correct, display a message from the possible responses to a correct answer below, and ask another multiplication question. If the answer is wrong, display a message from the possible responses to an incorrect answer below, and let the student try the same question repeatedly until the student finally gets it right. A separate method should be used to generate each new question. This method should be called once when the application begins execution and each time the student answers the question correctly. After the student gets five questions correctly, give him/her the opportunity to exit the program. The student might choose to continue, but after every correct answer thereafter, give him/her another opportunity to exit the program.

Possible responses to a correct answer: (Selected at random) Excellent! Very good! Nice work! Way to go! Keep up the good work!

Possible responses to an incorrect answer: (Selected at random) That is incorrect! No. Please try again! Wrong, Try once more! No. Don’t give up! No. Keep trying!

No input, processing or output should happen in the main method. All work should be delegated to other non-static methods. Include the recommended minimum documentation for each method. See the program one template for more details.


* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package multiply;

import java.security.SecureRandom;
import java.util.Scanner;

/**
*
* @author user1
*/
  

public class Multiply {
SecureRandom rand = new SecureRandom();
Scanner input = new Scanner(System.in);
int rand_int1 = rand.nextInt(10);// random integer 1
int rand_int2 = rand.nextInt(10);//random integer 2
int guess; //input from user
int result = rand_int1 * rand_int2; //correct answer
int questionNum = 0;
  
//import random number object
public static void main(String[] args) {
Multiply myObject = new Multiply();
myObject.question1();
myObject.question2();
myObject.question3();
myObject.question4();
myObject.question5();
}

//print a new question and stores the correct answer
public void question1() {
  
System.out.printf("How much is %d times %d ? ", rand_int1, rand_int2);
guess = input.nextInt();
  
  

if (guess != result)
System.out.println("That is incorrect");
else{
System.out.println("Excellent!");
question2();
}
  
}
public void question2(){
System.out.printf("How much is %d times %d?", rand_int1, rand_int2);
guess = input.nextInt();
  
while (guess != -1){
questionNum = questionNum +1;
if(result >= 5)
System.out.print("Enter -1 to exit program");


if (guess != result)
System.out.println("No. Please try again!");
else
System.out.println("Very good!");
question3();

}
  
}
public void question3(){
System.out.printf("How much is %d times %d?", rand_int1, rand_int2);
guess = input.nextInt();
  
while (guess != -1){
questionNum = questionNum +1;
if(result >= 5)
System.out.print("Enter -1 to exit program");


if (guess != result)
System.out.println("Wrong. Try once more!");
else
System.out.println("Nice work!");
question4();
}
  
}
public void question4(){
System.out.printf("How much is %d times %d?", rand_int1, rand_int2);
guess = input.nextInt();
  
while (guess != -1){
questionNum = questionNum +1;
if(result >= 5)
System.out.print("Enter -1 to exit program");
  
if(guess != result)
System.out.println("No. Dont give up!");
else
System.out.println("Way to go!");
question5();
  
}
  
}
public void question5(){
System.out.printf("How much is %d times %d?", rand_int1, rand_int2);
guess = input.nextInt();
  
while (guess != -1){
questionNum = questionNum +1;
if(result >= 5)
System.out.print("Enter -1 to exit program");
  
if (guess != result)
System.out.println("No. Keep trying!");
else
System.out.println("Keep up the good work! (press -1 to exit)");
question1();


}

  
}
  
  
}

0 1
Add a comment Improve this question Transcribed image text
Answer #1

/******************************Multiply.java*************************/

import java.security.SecureRandom;
import java.util.Scanner;

/**
*
* @author user1
*/

public class Multiply {

   public static void main(String[] args) {
       Multiply multiply = new Multiply();
       int totalCorrect = 0;
       char option = ' ';
       do {

           int num1 = multiply.getRandomNumber(10);
           int num2 = multiply.getRandomNumber(10);
           int msg = multiply.getRandomNumber(5);
           String question = multiply.getQuestion(num1, num2);
           System.out.print(question);
           if (multiply.isCorrect(num1, num2)) {

               System.out.println(multiply.getCorrectMsg(msg));
               totalCorrect ++;
           }
           else
               System.out.println(multiply.getWrongMsg(msg));
          
          
           if(totalCorrect==5) {
              
               option = multiply.wantToQuit();
           }
           if(option=='n') {
              
               break;
           }
          
       } while (!multiply.isContinue(option));

   }

   public int getRandomNumber(int limit) {

       SecureRandom randomNumbers = new SecureRandom();

       return randomNumbers.nextInt(limit) + 1;
   }

   public String getQuestion(int num1, int num2) {

       return "How much is " + num1 + " times " + num2 + "? ";

   }

   public String getCorrectMsg(int num) {

       if (num == 1) {

           return "Excellent!";
       } else if (num == 2) {

           return "Very good!";
       } else if (num == 3) {

           return "Nice work!";
       } else if (num == 4) {

           return "Way to go!";
       } else {

           return "Keep up the good work!";
       }
   }

   public String getWrongMsg(int num) {

       if (num == 1) {

           return "That is incorrect!";
       } else if (num == 2) {

           return "No. Please try again!";
       } else if (num == 3) {

           return "Wrong, Try once more!";
       } else if (num == 4) {

           return "No. Don’t give up!";
       } else {

           return "No. Keep trying!";
       }

   }

   public int getAnswer() {

       Scanner scan = new Scanner(System.in);
       return scan.nextInt();
   }

   public boolean isCorrect(int num1, int num2) {

       if (getAnswer() == num1 * num2) {

           return true;
       } else {

           return false;
       }
   }

   public boolean isContinue(char option) {

       if (option == 'y') {

           return true;
       } else {

           return false;
       }
   }

   public char wantToQuit() {

       Scanner scan = new Scanner(System.in);
       System.out.print("Do you want to continue(Y/N): ");
       return scan.nextLine().toLowerCase().charAt(0);
   }
}

/***********************output**********************/

How much is 9 times 3? 17
No. Don’t give up!
How much is 6 times 4? 24
Way to go!
How much is 10 times 5? 50
Keep up the good work!
How much is 8 times 5? 41
No. Don’t give up!
How much is 6 times 3? 18
Way to go!
How much is 10 times 4? 40
Keep up the good work!
How much is 4 times 9? 36
Very good!
Do you want to continue(Y/N): N

Console <terminated> Multiply (Java Application] C\ How much is 9 times 3? 17 No. Dont give up! How much is 6 times 4? 24 Wa

Please let me know if you have any doubt or modify the answer, Thanks :)

Add a comment
Know the answer?
Add Answer to:
So I can not get this to work properly and he does not want us using...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The following is the class definition for Multiplier. This class has five (5) members: two private...

    The following is the class definition for Multiplier. This class has five (5) members: two private instance variables two private methods one public method this is only public method for the class it calls other two private methods import java.util.*; //We need to use Scanner & Random in this package public class Multiplier {        private int answer; //for holding the correct answer        private Random randomNumbers = new Random(); //for creating random numbers        //ask the user to work...

  • I am getting an error from eclipse stating that: Exception in thread "main" java.lang.Error: Unresolved compilation...

    I am getting an error from eclipse stating that: Exception in thread "main" java.lang.Error: Unresolved compilation problem: at EvenOdd.main(EvenOdd.java:10) I am unable to find what I can do to fix this issue. Can you please assist? My code is below: import java.util.InputMismatchException; import java.util.Scanner; public class EvenOdd {    public static void main(String[] args) {        Scanner input = new Scanner(System.in);        System.out.println("Welcome to this Odd program!");        int userInput1 = input.nextInt();    }       public...

  • Can someone fix the program below so it does what the picture says it won't work...

    Can someone fix the program below so it does what the picture says it won't work for me. import java.util.Scanner; public class Userpass { static String arr[]; static int i = 0; public static void main(String[] args) { String username, password; int tries = 0, result; do { System.out.print("Enter the username: "); username = readUserInput(); System.out.print("Enter the password: "); password = readUserInput(); result = verifyCredentials(username, password); tries++; if (result == -1) System.out.println("The username is incorrect!\n"); else if (result == -2)...

  • Hi, So I have a finished class for the most part aside of the toFile method...

    Hi, So I have a finished class for the most part aside of the toFile method that takes a file absolute path +file name and writes to that file. I'd like to write everything that is in my run method also the toFile method. (They are the last two methods in the class). When I write to the file this is what I get. Instead of the desired That I get to my counsel. I am having trouble writing my...

  • IN JAVA: Write a program that displays a menu as shown in the sample run. You...

    IN JAVA: Write a program that displays a menu as shown in the sample run. You can enter 1, 2, 3, or 4 for choosing an addition, subtraction, multiplication, or division test. After a test is finished, the menu is redisplayed. You may choose another test or enter 5 to exit the system. Each test generates two random single-digit numbers to form a question for addition, subtraction, multiplication, or division. For a subtraction such as number1 – number2, number1 is...

  • How can I make this program sort strings that are in a text file and not...

    How can I make this program sort strings that are in a text file and not have the user type them in? I need this done by 5:00 AM EST tommorow please. import java.util.*; public class MergeDemo { public static void main(String args[]) { Scanner input=new Scanner(System.in); System.out.print("How many lines to be sorted:"); int size=input.nextInt(); String[] lines=new String[size]; lines[0]=input.nextLine(); System.out.println("please enter lines..."); for(int i=0;i { lines[i]=input.nextLine(); } System.out.println(); System.out.println("Lines Before Sorting:"); System.out.println(Arrays.toString(lines)); mergeSort(lines); System.out.println(); System.out.println("Lines after Sorting:"); System.out.println(Arrays.toString(lines)); } public...

  • I cant get the code to work. Any help would be appreciated. Instruction.java package simmac; public...

    I cant get the code to work. Any help would be appreciated. Instruction.java package simmac; public class Instruction { public static final int DW = 0x0000; public static final int ADD = 0x0001; public static final int SUB = 0x0002; public static final int LDA = 0x0003; public static final int LDI = 0x0004; public static final int STR = 0x0005; public static final int BRH = 0x0006; public static final int CBR = 0x0007; public static final int HLT...

  • Zeller's congruence is an algorithm developed to calculate the day of the week. Write a program...

    Zeller's congruence is an algorithm developed to calculate the day of the week. Write a program that prompts the user to enter a year, month, day of month and it displays the name of the week. Here is my source code. I need it broke down into a flowchart. public static void main(String[] args) {        //all variables are initialized to 0, because local variables require at least an initial value before use        Scanner input = new...

  • My Question is: I have to modify this program, even a small modification is fine. Can...

    My Question is: I have to modify this program, even a small modification is fine. Can anyone give any suggestion and solution? Thanks in Advanced. import java.util.*; class arrayQueue { protected int Queue[]; protected int front, rear, size, len; public arrayQueue(int n) { size = n; len = 0; Queue = new int[size]; front = -1; rear = -1; } public boolean isEmpty() { return front == -1; } public boolean isFull() { return front == 0 && rear ==size...

  • Java // Topic 2c // Program reserves airline seats. import java.util.Scanner public class Plane {    //...

    Java // Topic 2c // Program reserves airline seats. import java.util.Scanner public class Plane {    // checks customers in and assigns them a boarding pass    // To the human user, Seats 1 to 2 are for First Class passengers and Seats 3 to 5 are for Economy Class passengers    //    public void reserveSeats()    {       int counter = 0;       int section = 0;       int choice = 0;       String eatRest = ""; //to hold junk in input buffer       String inName = "";      ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT