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 50 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
Wow, this really help


xoxo123

  • Member
  • Posts: 335
Reply 3 on: Yesterday
YES! Correct, THANKS for helping me on my review

 

Did you know?

On average, the stomach produces 2 L of hydrochloric acid per day.

Did you know?

Cucumber slices relieve headaches by tightening blood vessels, reducing blood flow to the area, and relieving pressure.

Did you know?

The human body produces and destroys 15 million blood cells every second.

Did you know?

Immunoglobulin injections may give short-term protection against, or reduce severity of certain diseases. They help people who have an inherited problem making their own antibodies, or those who are having certain types of cancer treatments.

Did you know?

The word drug comes from the Dutch word droog (meaning "dry"). For centuries, most drugs came from dried plants, hence the name.

For a complete list of videos, visit our video library