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 55 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


kilada

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

 

Did you know?

Most strokes are caused when blood clots move to a blood vessel in the brain and block blood flow to that area. Thrombolytic therapy can be used to dissolve the clot quickly. If given within 3 hours of the first stroke symptoms, this therapy can help limit stroke damage and disability.

Did you know?

In the United States, an estimated 50 million unnecessary antibiotics are prescribed for viral respiratory infections.

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.

Did you know?

The most dangerous mercury compound, dimethyl mercury, is so toxic that even a few microliters spilled on the skin can cause death. Mercury has been shown to accumulate in higher amounts in the following types of fish than other types: swordfish, shark, mackerel, tilefish, crab, and tuna.

Did you know?

If you use artificial sweeteners, such as cyclamates, your eyes may be more sensitive to light. Other factors that will make your eyes more sensitive to light include use of antibiotics, oral contraceptives, hypertension medications, diuretics, and antidiabetic medications.

For a complete list of videos, visit our video library