Advanced Java Programming with Object-Oriented Programming Design VERY IMPORTANT
ID: 3729014 • Letter: A
Question
Advanced Java Programming with Object-Oriented Programming Design
VERY IMPORTANT NOTE!!: This program for the question below MUST USE at least 2 CLASSES, getters/setters, etc and other object-oriented design (OOD) concepts because I'm in a more advanced Java class that requires me to utilize the concepts mentioned above. Also, I need detailed, but brief comments to most, if not all of the code to explain what is being used in the code and what is does so I have a better understanding of the code. I've seen answers to the question below already posted, however they don't utilize object-oriented design (OOD) concepts such as a minumum of two classes, getters/setters, etc which is required for this advanced Java programming class. So please......answer the question and meet the requirements for this question. Basically, I need advanced Java object-oriented design concepts for simple programs so here's to hoping this works out and if it does, I'll give a thumbs up, I promise!!!
The use of computers in education is referred to as computer- assisted instruction ( CAI). Write a program that will help an elementary school student learn multiplication. Use the rand function to produce two positive one- digit integers. The program should then prompt the user 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 the message " Very good!" and ask another multiplication question. If the answer is wrong, display the message " No. Please try again." and let the student try the same question repeatedly until the student finally gets it right. A separate function should be used to generate each new question. This function should be called once when the application begins execution and each time the user answers the question correctly.
Explanation / Answer
//GenerateRandom.java
import java.util.Random;
public class GenerateRandom {
private int firstNumber;
private int secondNumber;
private int max=1000;
private int min=1;
public int getFirstNumber() {
return firstNumber;
}
public void setFirstNumber(int firstNumber) {
this.firstNumber = firstNumber;
}
public int getSecondNumber() {
return secondNumber;
}
public void setSecondNumber(int secondNumber) {
this.secondNumber = secondNumber;
}
/*This function generate random number between 1to 1000 and set it to the above member variable*/
public void generateRandomNumber() {
Random random = new Random(System.currentTimeMillis());
setFirstNumber(random.nextInt((max - min) + 1) + min);
setSecondNumber(random.nextInt((max - min) + 1) + min);
}
}
//MainClass.java
/*This is main program from where execution will start, run it and see the results*/
import java.util.Scanner;
public class MainClass {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
boolean flag=true;
System.out.println("Welcome to Quiz");
GenerateRandom generateRandom =new GenerateRandom();
generateRandom.generateRandomNumber();
int first = generateRandom.getFirstNumber();
int second=generateRandom.getSecondNumber();
int result=first*second;
System.out.println("How much is "+first+" times "+second+"?");
int yourAns=sc.nextInt();
if(result==yourAns) {
System.out.println("Very good!");
flag=false;
}
while(flag) {
System.out.println("How much is "+first+" times "+second+"?");
yourAns=sc.nextInt();
if(result==yourAns) {
System.out.println("Very good!");
flag=false;
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.