You are developing a new game in which different kinds of disks are played in pa
ID: 3789080 • Letter: Y
Question
You are developing a new game in which different kinds of disks are played in pairs on a game board. Two disks can be played whey they meet the following criteria:
1. Both disks are the same kind (i.e., instances of the same class)
2. Spotted disks have the same number of spots
3. Sided disks have the same number of sides
4. Colored disks are the same color
Write the four “canPlay” methods (do not write complete classes) indicated in the accompanying UML class diagram without duplicating code (in place of duplicating code, call the canPlay method in a super class). Note that the UML diagram is not complete - it just presents the information relevant to this problem. The typical Java equals method is similar to the canPlay method, but note the argument type in the UML class diagram below. See Horstmann and Cornell’s “recipe for writing the perfect equals method” for suggestions (especially for step 1).
Explanation / Answer
Here is the implementatio of methods
1) // first override equal method.
public boolean canPlay(){
boolean b=d1.equals()d2;// return true if object of same class.
}
2) public boolean noSpottedDisk(Object1,Objwect2){
int a=Object1.NoOfSpots;
int c=Object2.NoOfSpots;
if(a=c){return true;}
else false;
}
3)
public boolean noSidedDisk(Object1,Objwect2){
int a=Object1.NoOfSideds;
int c=Object2.NoOfSides;
if(a=c){return true;}
else false;
}
4) public boolean checkColor(Object1,Object2){
String s= Object1.color.toString();
String s1= Object2.color.toString();
if(s.equals(s1)){retuen true;}
else false;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.