Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Program: Write a class whose instances represent a single playing card from a deck of cards. Playing cards have two distinguishing properties: rank and

Java Program: Write a class whose instances represent a single playing card from a deck of cards. Playing cards have two distinguishing properties: rank and suit. Fix this source code: import java.util.Arrays; public class Card{ protected static final String[] Suits = {"spades", "clubs", "hearts", "diamonds"}; protected static final String[] Ranks = {"1","2","3","4","5","6","7","8","9","10","J","Q","K"}; private String cardRank; private String cardSuit; public Card(){ int randomRank = (int) (Math.random() * Ranks.length); int randomSuit = (int) (Math.random() * Suits.length); cardRank = Ranks[randomRank]; cardSuit = Suits[randomSuit]; } public Card(String cardRank, String cardSuit){ cardRank = cardRank.toLowerCase(); cardSuit = cardSuit.toLowerCase(); if(Arrays.asList(Ranks).contains(cardRank)) this.cardRank = cardRank; else this.cardRank = "Invalid Rank"; if(Arrays.asList(Suits).contains(cardSuit)) this.cardSuit = cardSuit; else this.cardSuit = "Invalid Suit"; } public void getCardRank(){ System.out.print(cardRank); } public void getCardSuit(){ System.out.print(cardSuit); } public void sayCard(){ getCardSuit(); System.out.print(" "); getCardRank(); System.out.println(""); } public void setCardRank(String cardRank){ if(Arrays.asList(Ranks).contains(cardRank)) this.cardRank = cardRank; } public void setCardSuit(String cardSuit){ if(Arrays.asList(Suits).contains(cardSuit)) this.cardSuit = cardSuit; } } 

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

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

4. Compare and contrast the practices of the two companies.

Answered: 1 week ago

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago