1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Kryger [21]
4 years ago
6

Create a Flash Card class. Flash Cards have a Question and an Answer, each of which are Strings. Your class should include a con

structor, toString() and equals() methods. Write a main() method that creates an array of three Flash Cards, and prints each of them.
Computers and Technology
1 answer:
xeze [42]4 years ago
6 0

Answer:

<u> FlashCard.java</u>

  1. public class FlashCard {
  2.    String Question;
  3.    String Answer;
  4.    public FlashCard(String q, String a){
  5.        this.Question = q;
  6.        this.Answer = a;
  7.    }
  8.    public String toString(){
  9.        String output = "";
  10.        output += "Question: " + this.Question + "\n";
  11.        output += "Answer: " + this.Answer;
  12.        return output;
  13.    }
  14.    public boolean equals(String response){
  15.        if(this.Answer.equals(response)){
  16.            return true;
  17.        }
  18.        else{
  19.            return false;
  20.        }
  21.    }
  22. }

<u>Main.java</u>

  1. public class Main {
  2.    public static void main(String[] args) {
  3.        FlashCard card1 = new FlashCard("What is highest mountain?", "Everest");
  4.        FlashCard card2 = new FlashCard("What is natural satelite of earth?", "Moon");
  5.        FlashCard card3 = new FlashCard("Who is the first president of US?", "George Washington");
  6.        FlashCard cards [] = {card1, card2, card3};
  7.        for(int i=0; i < cards.length; i++){
  8.            System.out.println(cards[i]);
  9.        }
  10.    }
  11. }

Explanation:

In FlashCard.java, we create a FlashCard class with two instance variable, Question and Answer (Line 2 - 3). There is a constructor that takes two input strings to initialize the Question and Answer instance variables (Line 5-8). There is also a toString method that will return the predefined output string of question answer (Line 10 - 15). And also another equals method that will take an input string and check against with the Answer using string equals method. If matched, return True (Line 17 -24).

In Main.java, create three FlashCard object (Line 3-5) and then put them into an array (Line 6). Use a for loop to print the object (Line 8-10). The sample output is as follows:

Question: What is highest mountain?

Answer: Everest

Question: What is natural satelite of earth?

Answer: Moon

Question: Who is the first president of US?

Answer: George Washington

You might be interested in
How many performance steps are involved in the process of completing a detainee?
Reika [66]
It looks like you've posted your question in wrong topic. Anyway I can help you. Performance steps for Guard Detainees and Completing a detainee are almost the same. If my memory serves me well, there are 6 performance steps. But the main rule is to be patient and ready for action. Always prepare your weapons to use, check if they are functional.
6 0
3 years ago
What is true about music from the Romantic period?
avanturin [10]
The answer to the given question above is the third option: <span>It was longer and less constrained than the music of the Classical period. The Romantic Period in music actually has more freedom in design and form. During this period, music were even more artistic and intellectual as well. Romantic Period occurred the late 18th century until early 19th century.</span>
8 0
3 years ago
Read 2 more answers
Operation code field is present in:
Tasya [4]
The answer is most likely C
6 0
3 years ago
When does personal information often need to be entered online?
soldi70 [24.7K]

Answer:

Like when your doing an application for a job or anything important lol

Explanation:

3 0
3 years ago
Allows an administrator to query a dns database and find the host name associated with a specific ip address or
Rom4ik [11]
  Or a domain name.   Good Luck!
6 0
4 years ago
Other questions:
  • When computers connect to one another to share information, but are not dependent on each other to work, they are connected thro
    7·1 answer
  • Good afternoon guys !!!
    14·2 answers
  • Write a program called DeliveryCharges for the package delivery service in Exercise 4. The program should again use an array tha
    9·1 answer
  • TRUE OR FALSE: If I ask you to span multiple rows in your table, that means that two columns will merge together
    5·1 answer
  • When troubleshooting firewalls, you should never attempt to repeat the problem because you could do more damage. T/F
    6·1 answer
  • Assume that the ciphertext C is computed from the plaintext P by C= P ⊕ K1 ⊕ K2 , where K1 and K2 are the encryption key and ⊕ d
    5·1 answer
  • Name the box where the name of the first cell of the selected range appears?
    7·1 answer
  • El planeamiento estratégico de una empresa es​
    9·1 answer
  • What are the three benefits of incremental development, compared to the waterfall<br> model?
    14·1 answer
  • MSWord is a popular___________ program.​
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!