



Code:
Test Class
import java.util.Collections;
/**
* @author
*
*/
public class Test {
/**
* @param args
*/
public static void main(String args[]) {
Deck deck = new Deck();
System.out.println(deck);
System.out.println("Size of deck is: "+deck.getSizeOfDeck());
deck.shuffle();
System.out.println("Deck after shuffling is "+deck);
Hand hand1 = new Hand();
for(int i = 0; i < 13; i++) {
hand1.hand.add(deck.dealCard());
System.out.println("Size of deck after dealing a card to player is "+deck.getSizeOfDeck());
System.out.println("Hand of player 1 is "+ hand1.getHand());
}
Collections.sort(hand1.hand, new Hand.CardComparator());
}
}
Card Class:
/**
* @author
*
*/
enum SUITE {
HEART,
SPADE,
CLUB,
DIAMOND
}
/**
* @author
*
*/
public class Card {
int rank;
SUITE suite;
/**
* @param value
* @param suite
*/
public Card(int value, SUITE suite) {
this.rank = value;
this.suite = suite;
}
/**
* @return
*/
public int getRank() {
return rank;
}
/**
* @return
*/
public int getSuite() {
return suite.ordinal();
}
/**
* @param value
*/
public void setRank(int value) {
this.rank = value;
}
/**
* @param suite
*/
public void setSuite(SUITE suite) {
this.suite = suite;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
char s = Character.MIN_VALUE;
switch(suite) {
case DIAMOND:
s='\u2666';
break;
case SPADE:
s='\u2660';
break;
case HEART:
s='\u2665';
break;
case CLUB:
s='\u2663';
break;
}
return "" + rank + s ;
}
}
Deck Class:
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
/**
* @author gopir
*
*/
/**
* @author gopir
*
*/
/**
* @author gopir
*
*/
/**
* @author gopir
*
*/
public class Deck {
List<Card> cards;
public Deck() {
this.cards = new ArrayList<Card>();
for(int value = 1 ; value <= 13 ; value++){
for(SUITE suite : SUITE.values()){
cards.add(new Card(value,suite));
}
}
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Deck{" +
"cardDeck=" + cards +
'}';
}
public void shuffle(){
Random rand = new Random();
//Generate two random numbers between 0 to 51
for(int i = 0 ; i < 20 ; i ++){
int card1 = rand.nextInt(52);
int secondCard = rand.nextInt(52);
Collections.swap(cards,card1,secondCard);
}
}
/**
* @return
*/
public Card dealCard(){
Card removedCard = cards.remove(0);
return removedCard;
}
//Size of the deck for testing purpose
/**
* @return
*/
public int getSizeOfDeck(){
return cards.size();
}
}
Hand Class:
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
/**
* @author
*
*/
public class Hand implements Comparable<Card>{
List<Card> hand;
public Hand() {
this.hand = new ArrayList<Card>();
}
/**
* @return
*/
public List<Card> getHand() {
return hand;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Player{" + "hand=" + hand + '}';
}
/**
* @author
*
*/
static class CardComparator implements Comparator<Card> {
/* (non-Javadoc)
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
public int compare(Card p1, Card p2) {
int rank1 = p1.getRank();
int suite1 = p1.getSuite();
int rank2 = p2.getRank();
int suite2 = p2.getSuite();
if (suite1 == suite2 && rank1 == rank2)
return 0;
else if (suite1 == suite2 && rank1 > rank2)
return 1;
else
return -1;
}
}
@Override
public int compareTo(Card o) {
return 0;
}
}
Please add your name whereever javadoc contains author.
Sample output1:
Deck{cardDeck=[1♥, 1♠, 1♣, 1♦, 2♥, 2♠, 2♣, 2♦, 3♥, 3♠, 3♣, 3♦, 4♥, 4♠, 4♣, 4♦, 5♥, 5♠, 5♣, 5♦, 6♥, 6♠, 6♣, 6♦, 7♥, 7♠, 7♣, 7♦, 8♥, 8♠, 8♣, 8♦, 9♥, 9♠, 9♣, 9♦, 10♥, 10♠, 10♣, 10♦, 11♥, 11♠, 11♣, 11♦, 12♥, 12♠, 12♣, 12♦, 13♥, 13♠, 13♣, 13♦]}
Size of deck is: 52
Deck after shuffling is Deck{cardDeck=[1♥, 12♦, 1♣, 3♥, 2♥, 9♣, 2♣, 2♦, 1♦, 3♠, 13♠, 3♦, 1♠, 4♠, 11♣, 6♠, 10♦, 5♠, 8♥, 5♦, 10♥, 4♥, 6♣, 12♠, 12♣, 7♠, 7♣, 7♦, 5♣, 8♠, 10♠, 13♣, 4♦, 9♠, 2♠, 9♦, 8♣, 6♥, 10♣, 11♥, 5♥, 11♠, 9♥, 11♦, 6♦, 12♥, 7♥, 4♣, 13♥, 3♣, 8♦, 13♦]}
Size of deck after dealing a card to player is 51
Hand of player 1 is [1♥]
Size of deck after dealing a card to player is 50
Hand of player 1 is [1♥, 12♦]
Size of deck after dealing a card to player is 49
Hand of player 1 is [1♥, 12♦, 1♣]
Size of deck after dealing a card to player is 48
Hand of player 1 is [1♥, 12♦, 1♣, 3♥]
Size of deck after dealing a card to player is 47
Hand of player 1 is [1♥, 12♦, 1♣, 3♥, 2♥]
Size of deck after dealing a card to player is 46
Hand of player 1 is [1♥, 12♦, 1♣, 3♥, 2♥, 9♣]
Size of deck after dealing a card to player is 45
Hand of player 1 is [1♥, 12♦, 1♣, 3♥, 2♥, 9♣, 2♣]
Size of deck after dealing a card to player is 44
Hand of player 1 is [1♥, 12♦, 1♣, 3♥, 2♥, 9♣, 2♣, 2♦]
Size of deck after dealing a card to player is 43
Hand of player 1 is [1♥, 12♦, 1♣, 3♥, 2♥, 9♣, 2♣, 2♦, 1♦]
Size of deck after dealing a card to player is 42
Hand of player 1 is [1♥, 12♦, 1♣, 3♥, 2♥, 9♣, 2♣, 2♦, 1♦, 3♠]
Size of deck after dealing a card to player is 41
Hand of player 1 is [1♥, 12♦, 1♣, 3♥, 2♥, 9♣, 2♣, 2♦, 1♦, 3♠, 13♠]
Size of deck after dealing a card to player is 40
Hand of player 1 is [1♥, 12♦, 1♣, 3♥, 2♥, 9♣, 2♣, 2♦, 1♦, 3♠, 13♠, 3♦]
Size of deck after dealing a card to player is 39
Hand of player 1 is [1♥, 12♦, 1♣, 3♥, 2♥, 9♣, 2♣, 2♦, 1♦, 3♠, 13♠, 3♦, 1♠]
Sample Output2:
Deck{cardDeck=[1♥, 1♠, 1♣, 1♦, 2♥, 2♠, 2♣, 2♦, 3♥, 3♠, 3♣, 3♦, 4♥, 4♠, 4♣, 4♦, 5♥, 5♠, 5♣, 5♦, 6♥, 6♠, 6♣, 6♦, 7♥, 7♠, 7♣, 7♦, 8♥, 8♠, 8♣, 8♦, 9♥, 9♠, 9♣, 9♦, 10♥, 10♠, 10♣, 10♦, 11♥, 11♠, 11♣, 11♦, 12♥, 12♠, 12♣, 12♦, 13♥, 13♠, 13♣, 13♦]}
Size of deck is: 52
Deck after shuffling is Deck{cardDeck=[7♣, 6♦, 1♣, 4♥, 2♥, 2♠, 3♣, 5♠, 10♥, 10♠, 2♣, 3♦, 13♦, 10♦, 4♣, 4♦, 8♥, 7♦, 6♥, 5♦, 5♣, 6♠, 7♠, 1♠, 7♥, 6♣, 10♣, 2♦, 5♥, 8♠, 8♣, 4♠, 13♠, 9♠, 3♥, 8♦, 9♣, 1♦, 11♥, 9♦, 1♥, 11♠, 11♣, 11♦, 12♥, 12♠, 12♣, 12♦, 13♥, 9♥, 13♣, 3♠]}
Size of deck after dealing a card to player is 51
Hand of player 1 is [7♣]
Size of deck after dealing a card to player is 50
Hand of player 1 is [7♣, 6♦]
Size of deck after dealing a card to player is 49
Hand of player 1 is [7♣, 6♦, 1♣]
Size of deck after dealing a card to player is 48
Hand of player 1 is [7♣, 6♦, 1♣, 4♥]
Size of deck after dealing a card to player is 47
Hand of player 1 is [7♣, 6♦, 1♣, 4♥, 2♥]
Size of deck after dealing a card to player is 46
Hand of player 1 is [7♣, 6♦, 1♣, 4♥, 2♥, 2♠]
Size of deck after dealing a card to player is 45
Hand of player 1 is [7♣, 6♦, 1♣, 4♥, 2♥, 2♠, 3♣]
Size of deck after dealing a card to player is 44
Hand of player 1 is [7♣, 6♦, 1♣, 4♥, 2♥, 2♠, 3♣, 5♠]
Size of deck after dealing a card to player is 43
Hand of player 1 is [7♣, 6♦, 1♣, 4♥, 2♥, 2♠, 3♣, 5♠, 10♥]
Size of deck after dealing a card to player is 42
Hand of player 1 is [7♣, 6♦, 1♣, 4♥, 2♥, 2♠, 3♣, 5♠, 10♥, 10♠]
Size of deck after dealing a card to player is 41
Hand of player 1 is [7♣, 6♦, 1♣, 4♥, 2♥, 2♠, 3♣, 5♠, 10♥, 10♠, 2♣]
Size of deck after dealing a card to player is 40
Hand of player 1 is [7♣, 6♦, 1♣, 4♥, 2♥, 2♠, 3♣, 5♠, 10♥, 10♠, 2♣, 3♦]
Size of deck after dealing a card to player is 39
Hand of player 1 is [7♣, 6♦, 1♣, 4♥, 2♥, 2♠, 3♣, 5♠, 10♥, 10♠, 2♣, 3♦, 13♦]
Sample Screesnhot:
![static class CardComparator implements Comparator<Card> [ /* (non-Javadoc) * @see java.util.comparator#compare(java.Lang.Object, java.lang.0bject) public int compare(Card p1, Card p2) 1 int rank1-p1.getRank; int suite1 p1.getSuite; int rank2-p2.getRank; int suite2 p2.getSuiteO); if (suitel suite2 & rank1rank2) else if (suitelsuite2 && rank1 > rank2) return 0; return 1; return -1; else @Override public int compareTo(Card o) £ return 0; R Markers画Properties Servers膼Data Source Explorer RS Snippets , problems console X <terminated> Main (2) [Java Application] /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/bin/j Size of deck after dealing a card to player is 49 Hand of player 1 is [7*, 6+, 1+] Size of deck after dealing a card to player is 48 Hand of player 1 is [7*, 6+, 1e, 4] Size of deck after dealing a card to player is 47 Hand of player 1 is [7*, 6+, 1e, 4v, 2»] Size of deck after dealing a card to player is 46 Hand of player 1 is [7*, 6+, 1e, 4v, 2», 2 ] Size of deck after dealing a card to player is 45 Hand of player 1 is [7*, 6+, 1*, 4v, 2v, 2*, 3»] Size of deck after dealing a card to player is 44 Hand of player 1 is [7*, 6+, 1e, 4», 2v, 2*, 3*, 5] Size of deck after dealing a card to player is 43 Hand of player 1 is [7a, 6+, le, 4. , 2., 24, 3, 54, 10.] Size of deck after dealing a card to player is 42 Hand of player 1 is [7a, 6+, le, 4v, 2., 24, 34, 54, 10v, 104] Size of deck after dealing a card to player is 41 Hand of player 1 is [7*, 6+, 1*, 4v, 2v, 2*, 3*, 5*, 10v, 10*, 2e] Size of deck after dealing a card to player is 40 Hand of player 1 is [7*, 6+, 1e, 4v, 2v, 2*, 3*, 5*, 10v, 10*, 2*, 3+] Size of deck after dealing a card to player is 39 Hand of player 1 is [7*, 6+, 1*, 4v, 2v, 2*, 3*, 5*, 10v, 10*, 2*, 3+, 13+]](http://img.homeworklib.com/questions/1bc9e1a0-3dc2-11eb-b529-532ae66eaaaa.png?x-oss-process=image/resize,w_560)
I used comparator to sort it. I added the logic to compare in compareTo method. If suite is same, check the numbers. That's the order. That's why you could see two different order of suites in the above outputs.
In case of any doubts, please comment.
Please use comment headers to specify what each section of code
does. The programming language is C.
Skeleton code:
Sample output:
Obiectives 1. To learn how to write functions given specifications 2. To learn how to the use pass by value and pass by reference variables 3. Review previous concepts like if-statements and loops. Movies about dragons and dragon training were very popular this summer. Your fiend has not stopped talking about how awesome dragons are and how cool it...
Write a code in matlab for AWGN () function. (please comment each line of the code to know what each line does)
Must comment on the code at every "/* Comment Here */" section about what the code is doing. import java.io.*; import org.xml.sax.*; import org.xml.sax.helpers.DefaultHandler; import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import java.util.Map; import java.util.HashMap; public class Configuration extends DefaultHandler { private Map map; private String configurationFile; /* Comment Here */ public Configuration(String configurationFile) throws ConfigurationException { this.configurationFile = configurationFile; map = new HashMap(); try { // Use the default (non-validating) parser SAXParserFactory factory = SAXParserFactory.newInstance();...
In python and without using Libraries (comment the code and please don't use lambda code): Write a function called mostfrequent that takes one string argument containing a list of words separated by commas (e.g., “apple,banana,apple,pear”, note there are no spaces). The function must return the word that occurs most frequently in the input string. You can assume there will be no ties in frequency. Examples: mostfrequent(“apple,apple,banana,apple,peach,banana”) “apple” mostfrequent(“apple,banana,banana,apple,peach,banana”) “banana” mostfrequent(“apple”) “apple”
Please explain each parameter passing method, when to use it, and code a function prototype example. a. Pass-by-rvalue b. Pass-by-const-lvalue-reference
C Language! Please, comment what each line of code does in the code below and answer this question: (sentence is fine) 1. Aside from pressing ctrl-(d/z) at the beginning of a line causing the getnchar() function to return NULL, is there any way to enter less than 9 characters? Code: void exer1(void) { char input[LEN]; char *check; getchar(); // Clearing character buffer. printf("Please enter 9 characters: "); // Prompting the user to enter // a specific input. ...
Python 3.7.2 for language Please comment for each line of code good naming is important 1. Answer the question: what is the Python regular expression pattern that would match a hex color (https://en.wikipedia.org/wiki/Web_colors ) (for example, the pattern that would match an email address is '[\w.-]+@[\w.-]') Write an algorithm for step 3. As part of your algorithm, be sure to describe the pattern you're using to find the win/loss result for each game. Write a program that looks at the...
Following code is a POSIX semaphore usage example. Fill in the
blanks.
(assume proper headers were al1 included) int main (int argc, char** argv) sem if (seminit (&sen, 0, 1) == -1) print f ("%s\n", strerror(errno): if printf ("*** Critical Section **n" İS: ( printf("* Non-Critical Section **n") if (semdestroy (&sem) '= 0) printf("%s\n", strerror (errno)); return 0 (&sem) ' 0) printf("%s\n", strerror (errno)); ( & sem) .- 0) printf ("%s\n", strerror (errno) ) ; -
CS 602 Server Side development hw1c please explain and comment the following html code <b>Employees with Last Name {{name}}</b> <hr/> <table border=1> <tr><th>Id</th><th>First Name</th><th>Last Name</th></tr> {{#each employees}} <tr> <td>{{this.id}}</td> <td>{{this.firstName}}</td> <td>{{this.lastName}}</td> <tr> {{/each}} </table> part two <!doctype html> <html> <head> <title>CS602 HW2</title> </head> <body> <header> <img src="/images/bu-logo.gif" alt="logo"> </header> <h3>CS602 HW2 - Your Name</h3> <a href="/addEmployee">Add Employee</a> <hr/> {{{body}}} </body>...
IN JAVA…PLEASE comment the code thoroughly so I can understand the thought process. Write a GUI application that converts Celsius temperatures to Fahrenheit temperatures. The user should be able to enter a Celsius temperature, click a button, and then see the equivalent Fahrenheit temperature. Use the following formula to make the conversion: F = (9/5)C + 32 F is the Fahrenheit temperature and C is the Celsius temperature. Instead of only converting from Celsius to Fahrenheit, also convert from Fahrenheit...