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
Who finds hacking code on the internet and click-and-point their way into systems to cause damage or spread viruses?
dem82 [27]
Anti Malware softwares or ex hackers
8 0
3 years ago
Thao tác trên mảng hai chiều với các yêu cầu sau đây: Khai báo mảng hai chiều; Nhập dữ liệu cho mảng hai chiều; Xuất theo dòng;
stepan [7]

Answer:

<h3>THIS SERVER IS FOR THE PEOPLES WHO'S ON THE UNITED STATES ONLY . IF U WANT US TO ANSWER YOUR QUESTION TRANSLATE IT TO ENGLISH </h3>
8 0
3 years ago
You have created a personal web page using a commercially available design program and web hosting site. The only items on your
maria [59]

Answer:

Notepad or Sublime text

Explanation:

These softwares enables you use and edit the website HTML, CSS and JavaScript code where necessary. Thank you.

4 0
3 years ago
Exercise 9.2.9: Strings To Integers5 points
netineya [11]

Answer:

x=input("Enter a String")

def safe_int(x):

   #lis1=[ int(x)if x.isdigit() else 0 for x in list_of_strings]

   lis1=[]

   lis1=x.split()

   print(lis1)

   flag=0

   j=0

   while(j in range(len(lis1))):

       if(lis1[j].isdigit()):

           flag==0

       else:

           flag==1

           try:

               if(int(lis1[j])):

                   lis1[j]=int(lis[j])

               else:

                   flag==1

                   break

           except:

               print("Cannot convert to integer")

       j+=1

   print(lis1)    

   

   

safe_int(x)

Explanation:

We are taking as an input a sentence, and then splitting it into various list items, and storing them in a list. Now we try to convert each item to integer and using try-except print the message cannot convert if its not possible or else converts it. As a check. enter 0 2 7 0   and also try Hello World.

5 0
3 years ago
Which from the following list are an example of productivity software?
Scorpion4ik [409]
D. All of the Above.....
3 0
4 years ago
Read 2 more answers
Other questions:
  • In what decade did the Internet begin to be used widely by the public and not just government entities?
    5·2 answers
  • Binary is best interpreted by a computer because?
    8·2 answers
  • Given the following method static void nPrint(String message, int n) { while (n &gt; 0) { System.out.print(message); n--; } } Wh
    12·1 answer
  • 1. If an F# function has type 'a -&gt; 'b when 'a : comparison, which of the following is not a legal type for it? Select one:
    14·1 answer
  • Rachel needs to include a new organizational chart in her project. Which type of illustration should she use?: *
    11·1 answer
  • How do you answer a brainly question on iPhone?
    8·1 answer
  • Can someone help me so I don’t fail this class:(
    14·1 answer
  • Leo needs to consolidate data in multiple worksheets by performing a calculation across all worksheets on the same cells.
    12·2 answers
  • The method used to transfer information to far off place instantly is called​
    13·2 answers
  • what is one category of software mentioned in the unit materials as being example of groupware English technical
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!