Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

edhesive Term 2 -Week 14 Write the code for a class, Location, to store the row

ID: 3707024 • Letter: E

Question

edhesive Term 2 -Week 14 Write the code for a class, Location, to store the row and column of an artifact in the grid. The maximum size of the grid should be 500x500. The class should include the following methods: 4. Location()-Default constructor initializes to location (0,0). Location(int r, int c) Constructor to create a location with row r and column c . int getRow) and int getCol-Getter methods which return the row and column of the location. void setRow(int r) and void setCol(int c) - Setter methods which modify the row and column of the ocation. (These should also make sure that the new location is within the maximum grid size) . boolean equals(Location o)- Comparison method which returns true iftwo locations have the same row and column.

Explanation / Answer

class Location{
    private int row;
    private int col;
    public Location(){
          row = 0;
          col = 0;
    }
    public Location(int r, int c){
           row = r;
           col = c;
    }
    public int getRow(){
           return row;
    }
    public int getCol(){
           return col;
    }
    public void setRow(int r){
       if (r <= 500)
           row = r;
    }
    public void setCol(int r){
       if (r <= 500)
           col = r;
    }
    public boolean equals(Location o){
        if (row == o.getRow() && col == o.getCol())
           return true;
        else
           return false;
    }      
   
}