Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MFDBS 89 2nd Symposium On Mathematical Fundamentals Of Database Systems Visegrad Hungary June 26 30 1989 Proceedings

Authors: Janos Demetrovics ,Bernhard Thalheim

1989th Edition

3540512519, 978-3540512516

More Books

Students also viewed these Databases questions