developing a card game that requires one deck of 52 cards using Java.  What I want is, from the code I've given, I want the program to perform the same but using comparator/comparable instead of hashmaps.   import java.util.HashMap; import java.io.*; public class CardPointsList { static HashMap Code = new HashMap<>(); static HashMap Order = new HashMap<>(); static String[][] hand= {{ "c5","s6","sK","dK","dA"},{"s7","s4","dJ","sA","h5"},{"sQ","d3","c9","hK","d5"}}; static int[] scores={0,0,0}; public static void sortHand() { String temp; for (int h=0;h<3;h++)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

I'm developing a card game that requires one deck of 52 cards using Java. 

What I want is, from the code I've given, I want the program to perform the same but using comparator/comparable instead of hashmaps.

 

import java.util.HashMap;

import java.io.*;
public class CardPointsList {
static HashMap<String,Integer> Code = new HashMap<>();
static HashMap<Character,Integer> Order = new HashMap<>();
static String[][] hand= {{ "c5","s6","sK","dK","dA"},{"s7","s4","dJ","sA","h5"},{"sQ","d3","c9","hK","d5"}};
static int[] scores={0,0,0};
public static void sortHand()
{ String temp;
for (int h=0;h<3;h++)
{for (int i=0;i<5;i++)
{ for (int j=i+1;j<5;j++)
{ if (hand[h][j].charAt(0) < hand[h][i].charAt(0))
{temp = hand[h][j];
hand[h][j] = hand[h][i];
hand[h][i] = temp;
}
else
if (hand[h][j].charAt(0) == hand[h][i].charAt(0))
{ if (Order.get(hand[h][j].charAt(1)) < Order.get(hand[h][i].charAt(1)))
{temp = hand[h][j];
hand[h][j] = hand[h][i];
hand[h][i] = temp;
}

}
} //for j

} // for i
}// for h

}

public static void printHand()
{ for (int h=0;h<3;h++) {
for (int i=0;i<5;i++)
{ System.out.println(hand[h][i]);}
System.out.println();
}
}

public static void getPoints( )
{ int[] suitScores = {0,0,0,0}; // holds the points for c,d,h,s suits, respectively.

for (int h=0;h<3;h++)
{
// calculate the point for each suit
for (int i=0;i<5;i++)
{ String myStr = Character.toString(hand[h][i].charAt(1));
String mySuit = Character.toString(hand[h][i].charAt(0));
if (mySuit.equals("c"))
suitScores[0] += Code.get(myStr);
if (mySuit.equals("d"))
suitScores[1]+= Code.get(myStr);
if (mySuit.equals("h"))
suitScores[2]+= Code.get(myStr);
if (mySuit.equals("s"))
suitScores[3]+= Code.get(myStr);

}
int max=0;
//find the max point which is the point for the hand
for (int j=0;j<4;j++)
{ if (suitScores[j]>max)
{ max=suitScores[j];}
suitScores[j]=0;
}
scores[h]=max;
System.out.println(scores[h]);

}

}

public static int getmax()
{ int max=0;
int handNum=0;
for (int h=0;h<3;h++)
{ if (scores[h]>max)
{max=scores[h];
handNum=h;
}

}
System.out.println("Maximum points :" + max);
return handNum+1;
}
public static void main(String[] args) throws IOException {
Code.put("A",1);
Code.put("2",2);
Code.put("3",3);
Code.put("4",4);
Code.put("5",5);
Code.put("6",6);
Code.put("7",7);
Code.put("8",8);
Code.put("9",9);
Code.put("X",10);
Code.put("J",10);
Code.put("K",10);
Code.put("Q",10);

Order.put('A',1);
Order.put('2',2);
Order.put('3',3);
Order.put('4',4);
Order.put('5',5);
Order.put('6',6);
Order.put('7',7);
Order.put('8',8);
Order.put('9',9);
Order.put('X',10);
Order.put('K',11);
Order.put('Q',12);
Order.put('J',13);

sortHand();
printHand();
getPoints();
int maxh=getmax();
System.out.println("Maximum points are for hand " + maxh);


}
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY