Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help to solve this assignment. CS 115 - Assignment 5 Abstract Class Inheritance For this homework assignment, you will extend the class PCard

I need help to solve this assignment.

CS 115 - Assignment 5

Abstract Class Inheritance

For this homework assignment, you will extend the class PCard and send your new card to a CardTest class to visually display your results. Both PCard and CardTest are provided. You cannot modify either of these files and your code will be tested against them. Your card class must support both rank and suit.

56-Card Deck

Your card class must support the standard 52 cards, plus the Knight. Information about a standard 52-card deck and the knight can be found at the following Wikipedia entries:

https://en.wikipedia.org/wiki/Standard_52-card_deckj

https://en.wikipedia.org/wiki/Knight_(playing_card)

Testing Output

Create a unit test to validate that all required card types are valid with your card class. You must also create a main method that uses the method run in CardTest to visually display results for a single card.

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

The 2 java file provided:

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

package test; import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.geom.Rectangle2D; import javax.swing.JFrame; import javax.swing.JPanel; import plumb.PCard; /**  * A simple playing card test. This test displays the given card in a window  * using Swing. The only method that needs to be called is run. The  * remaining methods and variables can be ignored.  *  * @author Jared N. Plumb  * @version 1.0  * @since 2018-05-25  */ public final class CardTest extends JPanel { /**  * Display a playing card in a window.  *  * @param card  * The card to display.  */  public static void run(PCard card) { EventQueue.invokeLater(new Runnable() { public void run() { JFrame frame = new JFrame(); frame.setTitle("Card"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false); frame.setLocationByPlatform(true); frame.add(new CardTest(card)); frame.pack(); frame.setVisible(true); } }); } // ********************************************************************** // Private Data // (You do not need to know anything below this point!) // ********************************************************************** private CardTest(PCard card) { this.setPreferredSize(new Dimension(GAME_WIDTH, GAME_HEIGHT)); this.setOpaque(true); this.setBackground(Color.WHITE); this.card = card; } public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(card.getBorderColor()); g2.fillRoundRect(CARD_X, CARD_Y, CARD_WIDTH, CARD_HEIGHT, 16, 16); g2.setColor(card.getFaceColor()); g2.fillRoundRect(CARD_X + 4, CARD_Y + 4, CARD_WIDTH - 8, CARD_HEIGHT - 8, 12, 12); g2.setFont(CARD_FONT); g2.setColor(card.getFontColor()); FontMetrics metrics = g2.getFontMetrics(); String text = card.getText(); Rectangle2D rect = metrics.getStringBounds(text, g2); g2.drawString(text, CARD_X + CARD_WIDTH / 2 - (int) rect.getWidth() / 2, CARD_Y + CARD_HEIGHT / 2 + metrics.getHeight() / 2 - metrics.getDescent()); } private static final long serialVersionUID = 447779152059287596L; private static final int GAME_WIDTH = 150; private static final int GAME_HEIGHT = 200; private static final int CARD_WIDTH = 100; private static final int CARD_HEIGHT = 150; private static final int CARD_X = (GAME_WIDTH - CARD_WIDTH) / 2; private static final int CARD_Y = (GAME_HEIGHT - CARD_HEIGHT) / 2; private static final Font CARD_FONT = new Font("SansSerif", Font.BOLD, 40); private final PCard card; } 

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

package plumb; import java.awt.Color; /**  * Base class used to create a playing card. This class is extended by another  * class that overrides the necessary methods to create usability and visual  * appeal.  *  * @author Jared N. Plumb  * @version 1.0  * @since 2018-05-25  */ public abstract class PCard { /**  * Returns a string containing both the rank and suit of the card. This text is  * used for visual display and may include Unicode characters.  */  public abstract String getText(); // Return a value such as "\u2605" /** Sets the card to the face up state. */  public void showCard() { } /** Sets the card to the face down state. */  public void hideCard() { } /**  * Finds if the card if face-down or face-up  *  * @return true if the card if face down.  */  public boolean isHidden() { return true; } /** Returns the color of the font used for the card text. */  public Color getFontColor() { return Color.LIGHT_GRAY; } /** Returns the color of the cards face. */  public Color getFaceColor() { return Color.WHITE; } /** Returns the color of the cards background. */  public Color getBackColor() { return Color.WHITE; } /** Returns the color of an 8 pixel border around the edge of the card. */  public Color getBorderColor() { return Color.LIGHT_GRAY; } /** Returns the alternative color used on the cards background. */  public Color getStripeColor() { return Color.LIGHT_GRAY; } } 

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

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions

Question

Solve for x: 2(3x 1)2(x + 5) = 12

Answered: 1 week ago

Question

=+Are you interested in working on global teams?

Answered: 1 week ago

Question

=+Do you want to work from home?

Answered: 1 week ago

Question

=+ What skills and competencies will enable someone

Answered: 1 week ago