Question: 1A. The class Client has a field cname that is of String type. It also has a field score of int type. B) The natural

1A. The class Client has a field cname that is of String type. It also has a field score of int type.

B) The natural order of Client is by name (alphabetical order). Write the code of the Client class, make it implements Comparable interface, and write the code of the compareTo method by comparing names. [Write correct class declaration, and implement the required method. You can skip the rest of the code for the class.]

C) Write the complete code of a Comparator class ByScore for this Client class. The ByScore class has the compare method comparing scores of two clients, and set a client of higher score ahead of the one of lower score.

D. Change and complete code the BySuitFirst class for Card type. You may use the helper methods.

Card class

Face-value first. The class is with some helper methods.

//helper method

int compFace(Card other) { //A before K before Q before J before 10..2

if (this.face.equals(other.face)) return 0;

else if (this.face.equals("A")) return -1;

else if (other.face.equals("A")) return 1;

else if (this.face.equals("K")) return -1;

else if (other.face.equals("K")) return 1;

else return other.num%13 - this.num%13; }

//helper method

int compSuit(Card other) {//spade before heart before diamond before club

if (this.suit.equals(other.suit)) return 0;

else if (this.suit.equals("spade")) return -1;

else if (other.suit.equals("spade")) return 1;

else if (this.suit.equals("heart")) return -1;

else if (other.suit.equals("heart")) return 1;

else if (this.suit.equals("diamond")) return -1;

else if (other.suit.equals("diamond")) return 1;

else return 0; }

//default order: by-face-first

public int compareTo(Card other) {

if (this.compFace(other) != 0) return

this.compFace(other);

else return this.compSuit(other); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!