Question
class Coord The coord class represents one row/column location on a board. It is intended to be used like an immutable pair of int values,
class Coord The coord class represents one row/column location on a board. It is intended to be used like an immutable pair of int values, so its only fields are final. This means we don't modify coordinates, we instead keep generating new coord objects based on old ones (translation: many of our methods will create and return another coord) public final int r, c methods public coord(int r, int c). Basic constructor. public coord up). Creates and returns a new coord that is one spot above the current spot (note: the row number gets smaller due to our chosen use of indexing!) public coord down(). Creates and returns a new coord that is one spot below the current spot. public coord left). Creates and returns a new coord that is one spot left of the current spot. public coord right ). Creates and returns a new coord that is one spot right the current spot. eoverride public String toString(). Creates and returns a string representation of the coord, which contains no spaces and follows the following pattern: (r,c). Examples: (0,o), (3,2). @override public boolean equals (Object other). An equality-check method which reports whether this object and other are both coord objects with the same r and c values or not. As this method tends to have some inheritance code involved, it is recommended to start with this template: @override public boolean equals (Object other) /7 first, check that the other is actually a Coord. if ( (other instanceof Coord)){ return false; // create a variable that remembers that other is a Coord, and not just the general object class Coord o = (Coord) other ; // TODO:check that they have the same r and c values. Manual Inspection Criteria (5%): follow the template for equals in each class that requires an equals method. Specifically, no shortcuts like comparing tostring() outputs are used
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started