ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 2 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 11 May 2017 My Price 9.00

Write a complete program that implements the functionality

Basic Requirements

Write a complete program that implements the functionality of a deck of cards. In writing your program, use the provided DeckDriver and Card classes shown below. Write your own Deck class so that it works in conjunction with the two given classes. Use anonymous objects where appropriate.

Deck class details:

Use an ArrayList to store Card objects.

Deck constructor:

The Deck constructor should initialize your ArrayList with the 52 cards found in a standard deck. Each card is a Card object. Each Card object contains two instance variables ─ num and suit. Study the Card class definition below for details.

dealCard:

This method removes the highest-indexed card in the ArrayList and returns it. In general, a method should not do more than what it’s supposed to do. Thus, dealCard should not print anything.

toString:

This method returns the deck’s contents using the format shown in the output session. In particular, note that toString should insert a newline after every fifth card. Hint: In coming up with a return value, use a String local variable. As you generate card values and newlines, concatenate those items to your local variable using the += operator.


Sample Session
Write your code such that the following classes produce the output shown in the subsequent output.
/*************************************************************
* DeckDriver.java
* 
* This class tests the Deck class.
*************************************************************/
public class DeckDriver
{
public static void main(String[] args)
{
Deck deck = new Deck();
System.out.println(deck.dealCard());
System.out.println(deck.dealCard());
System.out.println();
System.out.println(deck);
} // end main
} // end DeckDriver class
/****************************************************************
* Card.java
* 
* This class stores a Card's information.
****************************************************************/
public class Card
{
private int num; // hold a number between 1 and 13
private char suit; // holds 'C' for clubs, 'D' for diamonds,
// 'H' for hearts, 'S' for spades
//**************************************************
public Card(int num, char suit)
{
this.num = num;
this.suit = suit;
} // end Card constructor
//**************************************************
// Return the card's value in the form of a concatenated
// number and character.
// For example, 1C = ace of clubs, 12H = queen of hearts.
public String toString()
{
return Integer.toString(num) + suit;
}
} // end class Card

Answers

(11)
Status NEW Posted 11 May 2017 03:05 AM My Price 9.00

-----------

Attachments

file 1494471954-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)