Question: Questions are all related to Basic Card lab. 1. Draw the detailed UML class diagram of the class Card. 2. Draw the detailed UML class

Questions are all related to Basic Card lab.

1. Draw the detailed UML class diagram of the class Card.

2. Draw the detailed UML class diagram of the class BasicCardFrame.

3. List all Java library classes that BasicCardFrame class aggregates. How are they imported into the program?

4. The BasicCardFrame class imported the entire package of java.util. Is it really necessary? Can you replace it by importing a single class instead?

5. Which of the program files of the lab is an application? How can you tell?

6. If you want to put all classes you defined in Basic Cad lab in a package named myBasicCard, what changes you must make? Also draw the conceptual level diagram showing the package and the classes in it.

//file Card.java, bare-bone form

import javax.swing.ImageIcon;

public class Card {

private int num;

private String suit;

private String face;

private ImageIcon image;

public Card() {}

public Card(int n) {

num = n%52;

setCard();

}

public String getSuit(){ return suit;}

public String getFace() { return face;}

public ImageIcon getImage() { return image;}

private void setCard() {

int q = num/13;

int r = num % 13;

switch(q) {

case 0: { suit="spade"; break;}

case 1: { suit="heart"; break;}

case 2: { suit="diamond"; break;}

case 3: { suit="club"; break;} }

if (2 <= r && r <= 10) face = "" + r;

else

switch(r) {

case 11: { face="J"; break;}

case 12: { face="Q"; break;}

case 0: { face="K"; break;}

case 1: { face="A"; break;}

}

String fn = "cards\\200px-Playing_card_" + suit + "_" + face + ".svg.png";

image = new ImageIcon(fn);

}

public String toString(){

return suit + " " + face;

}

}

--------------------------------------

//card program, arry and array list

import javax.swing.*;

import java.awt.*;

import java.util.*;

import java.awt.event.*;

public class CardFrame extends JFrame {

ArrayList deck = new ArrayList();

int count=0;

String player_score = "start";

JPanel mainPanel = new JPanel();

JPanel playerPanel = new JPanel();

JLabel[] picLabel = new JLabel[4];

JTextArea playerField = new JTextArea();

JButton deal = new JButton("DEAL");

ActionListener action = new DealActionListener();

public CardFrame() {

super();

setSize(1000, 400);

setTitle("Card Program");

loadCard();

getContentPane().add(mainPanel, BorderLayout.CENTER);

getContentPane().add(playerPanel, BorderLayout.EAST);

getContentPane().add(deal, BorderLayout.SOUTH);

mainPanel.setLayout(new GridLayout(1, 4));

for (int i=0; i < 4; i++) {

picLabel[i] = new JLabel();

mainPanel.add(picLabel[i]);

}

playerField.setText(player_score);

playerPanel.add(playerField);

deal.addActionListener(action);

} //end constructor

private void loadCard() {

for (int k = 1; k <= 52; k++)

deck.add(new Card(k));

Collections.shuffle(deck);

}

public static void main(String[] args) {

CardFrame frame = new CardFrame();

frame.setDefaultLookAndFeelDecorated(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

} //end main

//inner class

class DealActionListener implements ActionListener {

public void actionPerformed(ActionEvent e) {

if (count == 4) {

for (int i = 0; i < 4; i++) {

picLabel[i].setIcon(null);

deck.remove(0);

}

player_score = player_score + " " + "again";

playerField.setText(player_score);

count = 0;

}

if (count < 4) {

Card c = deck.get(count);

picLabel[count].setIcon(c.getImage());

player_score = player_score + " " + c.toString();

playerField.setText(player_score);

count++;

}

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!