IN JAVA
Create the “MathTest” class. It will have two class variables: 1) a question and 2) the answer to that question.
Please create an accessor and mutator method for both of those variables, without which we would not be able to see or change the question or the answer.
There should be a constructor method. We will also have a “ToString” method, which will print the question followed by its answer.
The constructor method has two parameters to allow the user to enter a question and answer, or if no input/parameters are given then a default question and answer should be supplied (see exercise 4 for the default question and answer).
The last method of the class, CheckAnswer, should take in a string as a parameter and compare it to the answer. If the input was incorrect, it should return false. Otherwise, it should return true.
Create an instance of the “MathTest” class in your “main” method. First ask the user if they want to enter a question and answer.
If they do, then allow them to enter the test question and its answer.
If they do not, then continue by using the default question and answer.
The default question should be “Find the value of x in 4 = x ^ 2” and the default answer should be “2”. Please use the appropriate constructor methods here.
Then, using the “ToString” method, have it print out those class variables as described above.
Lastly, call the “CheckAnswer” method. You may either terminate the program at this point (if the user types “quit”) or allow for an infinite series of trivia games.
Example:
Would you like to use a default question (yes or no)? “no”
Please enter a test question: “What is the value of x in 56 / x = 14?”
Please enter the answer to that question: “4”
Your question was: “What is your favorite color?” and your answer was: “Blue”
Please enter your answer to the test question: “4”
Congratulations! You were correct.
Example using Default Question and Answer and with an Incorrect Answer:
Would you like to use a default question (yes or no)? “yes”
Please enter a test question: “”
Please enter the answer to that question: “”
Your question was: “Find the value of x in 4 = x ^ 2” and your answer was: “2”
Please enter your answer to the test question: “16”
I’m sorry, you were incorrect.
import java.io.*;
import java.util.*;
class MathTest {
String question;
String answer;
public MathTest(){
this.question = "Find the value of x in 4 = x ^ 2";
this.answer = "2";
}
public MathTest(String ques,String ans){
this.question=ques;
this.answer=ans;
}
public String getQuestion(){
return this.question;
}
public void setQuestion(String ques){
this.question = ques;
}
public String getAnswer(){
return this.answer;
}
public void setAnswer(String ans){
this.answer = ans;
}
public String ToString(){
return "Your question was: "+getQuestion()+"and your answer was:
"+getAnswer();
}
public void CheckAnswer(String ans){
if(ans.equals(getAnswer()))
System.out.println("Congratulations! You were correct.");
else
System.out.println("I'm sorry, you were incorrect.");
}
public static void main (String[] args) {
Scanner sc = new
Scanner(System.in);
String option2;
MathTest m;
do{
String
option1,question,answer,finalanswer;
System.out.println("Would you like
to use a default question (yes or no)?");
option1 = sc.nextLine();
if(option1.equals("yes"))
m = new MathTest();
else
{
System.out.print("Please enter a
test question: ");
question = sc.nextLine();
System.out.print("Please enter the
answer to that question:");
answer = sc.nextLine();
m = new
MathTest(question,answer);
}
m.ToString();
System.out.print("Please enter your
answer to the test question: ");
finalanswer = sc.nextLine();
m.CheckAnswer(finalanswer);
System.out.print("Enter 'quit' to
exit: ");
option2=sc.nextLine();
}while(!option2.equals("quit"));
}
}
Output:

IN JAVA Create the “MathTest” class. It will have two class variables: 1) a question and...
Exercise #3: Create the “MathTest” class. It will have two class variables: 1) a question and 2) the answer to that question. Exercise #4: Please create an accessor and mutator method for both of those variables, without which we would not be able to see or change the question or the answer. Exercise #5: There should be a constructor method. We will also have a “ToString” method, which will print the question followed by its answer. The constructor method has...
Using C# Create an instance of the “TestQuestion” class in your “main” method. Allow the user to enter the test question and its answer, if they want to. If they do not, then continue by creating a default question and answer. Please use the constructor methods here. Then, using the “ToString” or “__str__” method, have it print out those variables as described above. Lastly, call the “CheckAnswer” method and allow the user to continue attempting to answer the question until...
Urgent must be done in C# create an instance of the “ testquestion” class in your main method. allow the uswr to enter the teat question and its answer, it they want to. if they do not, then continue by creating a default queatuon and answer. please use the constructor methods here. Then, using the “tostring or _str_method, have it print out those variables as decribed above. call the “check answer” method and allow the user to continue attempting to...
In Java please Create a class to represent a dog. Name the class “Dog”. It will contain three (3) class attributes, its bark, size, and cuteness. The bark will be the sound of the dog’s bark, as in “woof!”. Its size will be how tall the dog is from the ground, and that number should always be between 6 and 44 inches. The cuteness is a string describing how cute the dog is, based on this scale: “ugliest dog ever!”...
QUESTION 3 (20) Create a constructor class Sum that has public integer variables num1 and num2. Include a default constructor and a method Add that accepts the two integer parameters, calculates and outputs the sum. In your main class Calculate include a main method that prompts the user to enter 2 integer values and create a reference called total for the constructor Sum. Output the values entered by the user and the sum of the values in the command line...
You will need to first create an object class encapsulating a Trivia Game which INHERITS from Game. Game is the parent class with the following attributes: description - which is a string write the constructor, accessor, mutator and toString methods. Trivia is the subclass of Game with the additional attributes: 1. trivia game id - integer 2. ultimate prize money - double 3. number of questions that must be answered to win - integer. 4. write the accessor, mutator, constructor,...
1- Create the base class Book that has the following instance variables, constructor, and methods title ( String) isbn ( String) authors (String) publisher (String) edition ( int) published_year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method // that return sting representation of Book object. 2- Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title ( String) isbn...
Exercise #3: Create a class to represent a dog. Name the class “Dog”. It will contain three (3) class attributes, its bark, size, and cuteness. The bark will be the sound of the dog’s bark, as in “woof!”. Its size will be how tall the dog is from the ground, and that number should always be between 6 and 44 inches. The cuteness is a string describing how cute the dog is, based on this scale: “ugliest dog ever!” “pretty...
JAVA LANG PACKAGE Create a NetBeans project for this activity. 1: Create a new class with attributes name and address. Both data type will be String. Create a constructor and assign the parameters to the attributes. Now override the to String() method. 2: Create a class with the main method and create an instance of the class that you created 3: Create an instance of the string in your test class and assign a value. 4: Now create an String...
C# programming
50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (String) edition ( int) published year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method// that return sting representation of Book object. 2-Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title...