create GUI Question Answer card program Create a data struc
create GUI Question & Answer card program
Create a data structure to hold a series of Q&A card objects. Objects have at leats two properties or attributes( question and a related answer) in addition to any other attributes and or methods needed. Hardcode in values for the card objects in the driver for your program.
The card data structure should be randomized. Each time the program is run the order of the card should be unique. Research to do this with few lines of code only.
GUI consist of a single JLabel and JButton. On starting, the JLabel should display a welcome message and a JButton should display \"Start\". After starting the first question should been displayed and the button should display Click for Answer. Upon the next Click the label should display the answer and the button should display Next Question.
After the last question as beed answered the program should display a dialog box asking the user if they want to go through the question again. The main button should be disabled.
Simply hard code the questions and answers into the program somewhere.
Solution
import java.io.*;
import java.util.*;
public class CardQandA{
string answer;
string question;
public value(string q, string a)
{
answer = a;
question = q;
}
}
class CardShelve{
string[13] rank; // assign rank from 1 to 13
string[4] suit; // assign suit from 1 to 4
ArrayList<CardQandA> Card;
Card()
{
Card = new ArrayList<CardQandA> Card;
for(int i=0;i<4;i++)
for(int j=0;j<13;j++)
Card.add(new Card(rank[j].suit[i]));
}
public void shuffle()
{
ArrayList<CardQandA> t = new ArrayList<CardQandA>();
while(!Card.isEmpty())
{
int location = (int)Math.random()*deck.size()); //
Card.remove(location);
t.add(Card.get(loaction));
}
Card = t;
}
}
class UI{
JButton button, question, answer;
JLabel label;
void buttonPannel(){
label = new JLabel(\"Welcome\");
button = new JButton(\"Start\");
button.addActionListener(new ButtonListener());
panel.add(button);
answer = new JButton(\"Click for Answer\");
answer.addActionListener(new ButtonListener());
label = new JLabel(\"Answer\");
question = new JButton(\"Next Question\");
question.addActionListener(new ButtonListener());
}
}
}

