x
Info
x
Warning
x
Danger
 / 
 / 
 / 
6)Assume a class Foo implements Comparable.  Without knowing anything else

Question : 6)Assume a class Foo implements Comparable.  Without knowing anything else : 2015384

6)Assume a class Foo implements Comparable.  Without knowing anything else about the Foo class, write an equals method that returns true if the Foo parameter passed to this Foo is equal to this Foo as determined by using the implementation of Comparable.

7)Write code that outputs all elements of iter, one per line.

8)Write a method that receives an int parameter and removes the item from iter at that location, where the first item is numbered location 1.  For instance, if the parameter is 3, the 3rd item is removed.  If the parameter is out of bounds (less than 1 or too large for the number of items in iter), then the method should output a message indicating this.

9)To implement Comparable for the ChessPiece class, the current ChessPiece’s type is compared to a ChessPiece passed as a parameter.  The method should return 0 if the types are equal, -1 if this piece’s type is a lesser piece than the parameter’s type, and 1 if this piece’s type is a greater piece than the parameter’s type.  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.”  Write the proper method to implement Comparable for this class.

10)Write a static method that is passed two ChessPieces and determines if the two pieces are owned by the same player.  It should return true or false.

Solution
5 (1 Ratings )

Solved
Computer Science 4 Years Ago 206 Views
This Question has Been Answered!

Related Answers
Unlimited Access Free
Explore More than 2 Million+
  • Textbook Solutions
  • Flashcards
  • Homework Answers
  • Documents
Signup for Instant Access!
Ask an Expert
Our Experts can answer your tough homework and study questions
154368 Computer Science Questions Answered!
Post a Question