Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Main topics: Writing Classes Declaring / Using Instance Variables Writing Instance Methods Accessors and Mutators Constructors public vs private Program Specification: 1. You are

Java

Main topics:

Writing Classes

Declaring / Using Instance Variables

Writing Instance Methods

Accessors and Mutators

Constructors

public vs private

Program Specification:

1. You are to first to write a Class named Card.

Card.java

A simple class which models a single playing card (from the deck of cards that has been described in Howeworks 1 and 2) by its two defining characteristics, which are its suit and its rank. Your Card class must adhere to the following:

(a) All instance variables must be private

(b) Include the standard public accessors

(c) Include the standard private mutators You must not set suit nor rank to something that is not in the domain of the mapping that is inherent to your String toString() method. Do nothing when an argument is invalid.

(d) All access of instance data by the other instance methods is made via the accessors and mutators.

(e) Include the standard default constructor By default a Card is the Ace of Clubs.

(f) Include the standard specifying constructor

(g) Contain a method Card clone() which creates and return a reference to a copy of the calling Card object.

(h) Contain a method boolean equals(Card guest) which returns whether or not guest has the same suit and rank as the calling Card object.

(i) Contain a method String toString() which returns a String representation of the calling Card objects suit and rank in some reasonable format.

2. You are then to write a Class named CardDriver.

CardDriver.java

A simple class which tests Your Card class by carrying out the following actions:

(a) Declare and create an array of Card, of size 52 (A deck).

(b) Fill the deck with the 52 unique playing cards (in any order).

(c) Apply 100 random transpositions of cards to the deck. A transposition:

Generate two random indices (each in the range 0 to 51)

Swap the two cards at these indices.

(d) Display the contents of the deck, from index 0 to index 51.

(e) Find and display the index of the Queen of clubs in the deck.

Sample run(s):

The Queen of clubs was found at location 42

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

More Books

Students also viewed these Databases questions