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 54 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!


Viet Thy

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

 

Did you know?

The average adult has about 21 square feet of skin.

Did you know?

Prostaglandins were first isolated from human semen in Sweden in the 1930s. They were so named because the researcher thought that they came from the prostate gland. In fact, prostaglandins exist and are synthesized in almost every cell of the body.

Did you know?

The U.S. Preventive Services Task Force recommends that all women age 65 years of age or older should be screened with bone densitometry.

Did you know?

Parkinson's disease is both chronic and progressive. This means that it persists over a long period of time and that its symptoms grow worse over time.

Did you know?

The use of salicylates dates back 2,500 years to Hippocrates’s recommendation of willow bark (from which a salicylate is derived) as an aid to the pains of childbirth. However, overdosage of salicylates can harm body fluids, electrolytes, the CNS, the GI tract, the ears, the lungs, the blood, the liver, and the kidneys and cause coma or death.

For a complete list of videos, visit our video library