This topic contains a solution. Click here to go to the answer

Author Question: For the questions below, consider a class called ChessPiece. This class has two instance data, ... (Read 61 times)

maychende

  • Hero Member
  • *****
  • Posts: 556
For the questions below, consider a class called ChessPiece.  This class has two instance data, String type and int player.  The variable type will store "King", "Queen", "Bishop", etc and the int player will store 0 or 1 depending on whose piece it is.  We wish to implement Comparable for the ChessPiece class.  Assume that, the current ChessPiece is compared to a ChessPiece passed as a parameter.  Pieces are ordered as follows:  "Pawn" is a lesser piece to a "Knight" and a "Bishop", "Knight" and "Bishop" are equivalent for this example, both are lesser pieces to a "Rook" which is a lesser piece to a "Queen" which is a lesser piece to a "King."


Which of the following pieces of logic could be used in the method that implements Comparable?  Assume that the method is passed Object a, which is really a ChessPiece.  Also assume that ChessPiece has a method called returnType which returns the type of the given piece.  Only one of these answers has correct logic.
◦ if (this.type < a.returnType( )) return -1;
◦ if (this.type = = a.returnType( )) return 0;
◦ if (this.type.equals(a.returnType( )) return 0;
◦ if (a.returnType( ).equals("King")) return -1;
◦ if (a.returnType( ).equals("Pawn")) return 1;


Related Topics

Need homework help now?

Ask unlimited questions for free

Ask a Question
Marked as best answer by maychende on Aug 30, 2020

JCABRERA33

  • Sr. Member
  • ****
  • Posts: 344
Lorsum iprem. Lorsus sur ipci. Lorsem sur iprem. Lorsum sur ipdi, lorsem sur ipci. Lorsum sur iprium, valum sur ipci et, vala sur ipci. Lorsem sur ipci, lorsa sur iprem. Valus sur ipdi. Lorsus sur iprium nunc, valem sur iprium. Valem sur ipdi. Lorsa sur iprium. Lorsum sur iprium. Valem sur ipdi. Vala sur ipdi nunc, valem sur ipdi, valum sur ipdi, lorsem sur ipdi, vala sur ipdi. Valem sur iprem nunc, lorsa sur iprium. Valum sur ipdi et, lorsus sur ipci. Valem sur iprem. Valem sur ipci. Lorsa sur iprium. Lorsem sur ipci, valus sur iprem. Lorsem sur iprem nunc, valus sur iprium.
Answer Preview
Only 49% of students answer this correctly




maychende

  • Member
  • Posts: 556
Reply 2 on: Aug 30, 2020
Gracias!


duy1981999

  • Member
  • Posts: 341
Reply 3 on: Yesterday
Thanks for the timely response, appreciate it

 

Did you know?

Medication errors are three times higher among children and infants than with adults.

Did you know?

About 80% of major fungal systemic infections are due to Candida albicans. Another form, Candida peritonitis, occurs most often in postoperative patients. A rare disease, Candida meningitis, may follow leukemia, kidney transplant, other immunosuppressed factors, or when suffering from Candida septicemia.

Did you know?

Disorders that may affect pharmacodynamics include genetic mutations, malnutrition, thyrotoxicosis, myasthenia gravis, Parkinson's disease, and certain forms of insulin-resistant diabetes mellitus.

Did you know?

Looking at the sun may not only cause headache and distort your vision temporarily, but it can also cause permanent eye damage. Any exposure to sunlight adds to the cumulative effects of ultraviolet (UV) radiation on your eyes. UV exposure has been linked to eye disorders such as macular degeneration, solar retinitis, and corneal dystrophies.

Did you know?

The Food and Drug Administration has approved Risperdal, an adult antipsychotic drug, for the symptomatic treatment of irritability in children and adolescents with autism. The approval is the first for the use of a drug to treat behaviors associated with autism in children. These behaviors are included under the general heading of irritability and include aggression, deliberate self-injury, and temper tantrums.

For a complete list of videos, visit our video library