Question

Urgent must be done in C# create an instance of the “ testquestion” class in your main method. al...

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 answer the question until they are correct. if they are correct the method should work as above and allow them to enter a new question and answer. you may either terminate the program at this program at this point (if the user types “quit”) or allow for an infinite series of trivia games

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

/*

In visual studio create a c# console app and name it CosoleApp1 and paste the following code in it and run the program.

*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
class testquestion
{
private string question, answer;
public testquestion()
{
this.question = "how many days are there in a leap year?";
this.answer = "365";
}
public testquestion(string question, string answer)
{
this.question = question;
this.answer = answer;
}
public void set_question(string question, string answer)
{
this.question = question;
this.answer = answer;
}
public bool check_answer(string answer)
{
return this.answer.Equals(answer);   
}
public override string ToString()
{
return String.Format("Question: {0}\nAnswer: {1}\n", question, answer);
}
static void Main(string[] args)
{
testquestion qa;
while(true)
{
Console.WriteLine("1. Enter new question(Hit enter to skip) or type quit to exit:");
string question = Console.ReadLine();
if (question.Equals("quit")) break;
if(!question.Equals(""))
{
Console.WriteLine("1. Enter answer:");
string answer = Console.ReadLine();
qa = new testquestion(question, answer);
}
else
{
qa = new testquestion();
}
Console.WriteLine(qa);
string ans;
do
{
Console.WriteLine("1. Enter answer of current question: ");
ans = Console.ReadLine();
}
while (!qa.check_answer(ans));
  
}
}
}
}

Quick Launch (Ctri+Q) ConsoleApp1 (Running) - Microsoft Visual Studio File Edit View Project Build Debug Team Tools Test AnalD Quick Launch (Ctri+Q) ConsoleAppl- Microsoft Visual Studio Eile Edit View Project Build Debug Team Tools Test Analyze岦indowQuick Launch (Ctri+Q) ConsoleAppl- Microsoft Visual Studio Eile Edit View Project Build Debug Team Tools Test Analyze岦indow H

Add a comment
Know the answer?
Add Answer to:
Urgent must be done in C# create an instance of the “ testquestion” class in your main method. al...
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
  • Using C# Create an instance of the “TestQuestion” class in your “main” method. Allow the user...

    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...

  • IN JAVA Create the “MathTest” class. It will have two class variables: 1) a question and...

    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...

  • Exercise #3: 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...

  • You are to create a class Appointment.java that will have the following: 5 Instance variables: private...

    You are to create a class Appointment.java that will have the following: 5 Instance variables: private String month private int day private int year private int hour private int minute 1 default constructor public Appointment() 1 non-default constructor that accepts arguments for all instance variables, your constructor must call the setter methods below to set the values of the instance variables public Appointment(String monthPassed, int dayPassed, int yearPassed, int hourPassed, int minutePassed) 5 setter methods (one for each instance variable)...

  • In Java Main method Your main program will prompt the user for a test name and...

    In Java Main method Your main program will prompt the user for a test name and the number of scores the user will enter. After creating an arraylist to hold the scores, prompt the user for all the scores to hold in the arraylist. After all the scores are entered, then repeat back the score & letter grade. GradeBook Object Create an instance of a GradeBook object and pass the test name and arraylist to set the instance variables. At...

  • Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters...

    Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...

  • Answer the following: 1.        Create a Class Car with the following instance variables: model (String), Brand...

    Answer the following: 1.        Create a Class Car with the following instance variables: model (String), Brand (String), maxspeed (double) Note: use encapsulation (all variables are private). (3 Marks) 2.        Create a non-default constructor for Class Car which takes 3 parameters. (2 Marks) 3.        Create a get and set methods for instance variable model variable only. (2 Marks) 4.        Create PrintInfo() method which prints all three instance variables. (2 Marks) 5.        Create a subclass GasCar with instance variable TankSize (double).. (2...

  • 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 (Strin...

    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...

  • Write the Java code for the class WordCruncher. Include the following members:

    **IN JAVAAssignment 10.1 [95 points]The WordCruncher classWrite the Java code for the class WordCruncher. Include the following members:A default constructor that sets the instance variable 'word' to the string "default".A parameterized constructor that accepts one String object as a parameter and stores it in the instance variable. The String must consist only of letters: no whitespace, digits, or punctuation. If the String parameter does not consist only of letters, set the instance variable to "default" instead. (This restriction will make...

  • Exercise #3: Create a class to represent a dog. Name the class “Dog”. It will contain...

    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...

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