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 62 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
Excellent


ricroger

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

 

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?

By definition, when a medication is administered intravenously, its bioavailability is 100%.

Did you know?

Elderly adults are living longer, and causes of death are shifting. At the same time, autopsy rates are at or near their lowest in history.

Did you know?

Over time, chronic hepatitis B virus and hepatitis C virus infections can progress to advanced liver disease, liver failure, and hepatocellular carcinoma. Unlike other forms, more than 80% of hepatitis C infections become chronic and lead to liver disease. When combined with hepatitis B, hepatitis C now accounts for 75% percent of all cases of liver disease around the world. Liver failure caused by hepatitis C is now leading cause of liver transplants in the United States.

Did you know?

The effects of organophosphate poisoning are referred to by using the abbreviations “SLUD” or “SLUDGE,” It stands for: salivation, lacrimation, urination, defecation, GI upset, and emesis.

For a complete list of videos, visit our video library