Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Drawing a blank and looking for a quick fix. Can you help me make my output look like the one below?? Currently it looks like

Drawing a blank and looking for a quick fix. Can you help me make my output look like the one below??

image text in transcribed

Currently it looks like this:

Welcome to Celebrity Cards!! Would you like to: 1. Shuffle? 2. Deal? 3. End? 1 Welcome to Celebrity Cards!! Would you like to: 1. Shuffle? 2. Deal? 3. End? 2 Lady Gaga ---------- Heart 9 Heart 2 Diamond Ace Diamond Jack Diamond 8 Diamond 4 Diamond 3 Spade Ace Spade 6 Spade 5 Spade 3 Club Queen Club 5

Albert Einstien ---------- Heart Queen Heart 8 Heart 3 Diamond 10 Diamond 5 Spade Queen Spade 9 Spade 7 Spade 2 Club 9 Club 6 Club 4 Club 2

Muhammed Ali ---------- Heart Ace Heart Jack Heart 10 Diamond King Diamond Queen Diamond 7 Diamond 6 Spade King Spade Jack Spade 4 Club Ace Club Jack Club 10

Diego Maradona ---------- Heart King Heart 7 Heart 6 Heart 5 Heart 4 Diamond 9 Diamond 2 Spade 10 Spade 8 Club King Club 8 Club 7 Club 3

Club Two - player 11 card 12 Welcome to Celebrity Cards!! Would you like to: 1. Shuffle? 2. Deal? 3. End?

package card;

import java.util.ArrayList; import java.util.List; import java.util.Scanner;

public class main {

public static void main(String args[]) { DeckMembers deck = new DeckMembers(); ArrayList players = new ArrayList(); Scanner userInput = new Scanner(System.in);

int choice;

do { System.out.println("Welcome to Celebrity Cards!!"); System.out.println("Would you like to:"); System.out.println("1. Shuffle?"); System.out.println("2. Deal?"); System.out.println("3. End?");

choice = userInput.nextInt(); if (choice == 1) { deck.shuffle(); }

if (choice == 2) { String[] names = new String[]{"Lady Gaga", "Albert Einstien", "Muhammed Ali", "Diego Maradona"}; for (int i = 0; i

} for(Player x: players){ System.out.println(x.getName()); System.out.println("----------");

for(Card card: x.getHand()){ System.out.println(card); } System.out.println(""); }

for (int i = 0; i

} } } while (choice != 3); }

}

package card;

import java.util.List;

public class Player {

private List hand; private String name;

public Player(String name) { this.name = name; }

private void sort() { for (int i = 0; i

Card card1 = hand.get(i); Card card2 = hand.get(j);

if (Card.compareCard(card1, card2)) { hand.set(i, card2); hand.set(j, card1); }

} } }

/* public void selectionSort(){ int i; int j; int indexSmallest; int temp;

for (i = 0; i

// Find index of smallest remaining element indexSmallest = i; for (j = i + 1; j

if (card1[j]

// Swap numbers[i] and numbers[indexSmallest] temp = numbers[i]; numbers[i] = numbers[indexSmallest]; numbers[indexSmallest] = temp; } } */ public int clubTwo() { for (int i = 0; i

if (card.getSuit().equals(Card.Suit.Club) && card.getNumber() == 2) { return i; } } return -1; }

public List getHand() { return hand; }

public void setHand(List hand) { this.hand = hand; this.sort(); }

public String getName() { return name; }

}

package card;

import java.util.ArrayList; import java.util.List; import java.util.Random;

public class DeckMembers { private List cards; public DeckMembers() { cards = new ArrayList();

for(Card.Suit suit : Card.Suit.values()) { for(int i = 1; i

Card card = new Card(suit, i);

cards.add(card); } } } public void shuffle() { Random random = new Random(); random.nextInt();

for (int i = 0; i

Card card = cards.get(i); cards.set(i, cards.get(x)); cards.set(x, card); } }

public List getCards() { return cards; } }

package card;

public class Card {

public enum Suit {Club, Spade, Diamond, Heart}; private int number; private Suit suit; private String description; public Card(Suit suit, int number){ this.suit = suit; this.number = number; switch (number) { case 1: description = suit + " Ace"; break; case 11: description = suit + " Jack"; break; case 12: description = suit + " Queen"; break; case 13: description = suit + " King"; break; default: description = Integer.toString(number); description = suit + " " + description; break; }

}

public static boolean compareCard(Card card1, Card card2){ if(card1.suit.equals(card2.suit)){ if(card1.number == 1) return false; else if(card2.number == 1) return true;

else return card1.number

else {

if(card1.suit.compareTo(card2.suit)

else return false;

}

}

public Suit getSuit() { return suit;

}

public int getNumber() { return number;

}

@Override public String toString() { return description;

}

public String getDescription(){ return description; }

}

Homework 2-The Deal Write a program that creates a deck of cards, shuffles it, and deals cards to each of four players. First display a menu, asking if user wants to shuffle, deal, or end. After each deal, display cards of each player in sorted order, followed by the location of the Club Two Lady Gagda Albert Einstein Muhammed Ali Diego Maradona Spade Ace Spade 10 Spade 5 Heart King Heart Queen Heart 10 Heart 8 Heart 4 Heart 3 Heart 2 Diamond 7 Qub Jack Qub 8 Spade Jack Spade 8 Spade 4 Spade 3 Heart Ace Heart Jock Heart 9 Diamond Ace Diamond 10 Diamond3 Club 9 Club 7 Club 4 Spade 6 Spade 2 Diamond King Diamond Queen Diamond Jack Diamond 9 Diamond 8 Diamond 6 Diamond 5 Club King Club 10 Club 6 Club 2 Spade King Spade Queen Spade 9 Spade 7 Heart 7 Heart 6 Heart 5 Diamond 4 Diamond 2 Club Ace Club Queen Club 5 Club 3 lub Two - player 3 card 13 Begin with your code from the Deck of Cards Lab. Your program should have three classes, each in a separate file, with these members: Card members suit - enumerated data type for SPADE, HEART, DIAMOND, CLUB number- integer between 1 and 13 description string containing name of card, such as Heart Ace boolean compare(Card card1, Card card2) - returns true if the card1 is less than' card2 false if not, using these rules 1. Regardless of card number, clubs

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

Students also viewed these Databases questions