I need help with this Java program over a Cell class program shown below detailed in the given image: This is the Java code (Cell class)that need fixed with help of both the given image and the interface guide - package classPackage; import java.util.ArrayList; import interfaces.CellInterface; import interfaces.RatInterface; /** * @author Owner * */ public class Cell implements CellInterface { privatefinalint [] location; private ArrayList ratHouse = new ArrayList (); public Cell(int[] pLocation) { location = pLocation.clone(); } @Override publicchar getCellType() { // TODO Auto-generated method stub return 0; } @Override publicint[] receiveRat(RatInterface pRat) { pRat.wearDown(); if (Math.random()<.2) pRat.refresh(); ratHouse.add(pRat); returnlocation.clone(); } @Override public RatInterface retrieveRat() { /** * The storeTheDead(Rat pRat) method stores the argument Rat in a list of dead rats. * precondition: pRat must reference a Rat object, a list structure of some kind that stores rats, must exist. * postcondition: pRat's reference is added to a list of dead rats. * @param pRat */ returnratHouse; } @Override publicvoid storeTheDead(RatInterface pRat) { /** * The returnTheDead() method retrieves a list of the rats that died in the cell. * @precondition The dead rat ArrayList must exist though it need not have any rats in it. * @postcondition none * @return * ArrayList<> of Rat objects. */ } @Override public ArrayList returnTheDead() { // TODO Auto-generated method stub returnnull; } } The interface code that has directions that needs to be inputted in the cell class code - package interfaces; import java.util.ArrayList; /** * @author Owner * */ public interface CellInterface { int[] location = newint[2]; /** * The getCellType() returns the cell type * @Precondition The cell type must be initialized as a final variable during the construction of a cell object. * It should indicate one of the four cell types Cell, Hole, Waste, or Shelter * @Postcondition no change * @return a character for the cell type */ publicchar getCellType(); /** * The receiveRat() method receives a rat and stores the rat * @param RatInterface holds reference to Rat object * @return * Returns {row,col} * cell location if rat is accepted and stored * -1, -1 if there is no space to hold the rat * */ publicint[] receiveRat(RatInterface pRat); /** * The retrieveRat(String pRatID) method receives a rat ID and returns the reference to that rat if the rat is stored in the cell * @param RatID holds String ID of Rat object * @return Returns the reference to a Rat object if there is one in the cell */ public RatInterface retrieveRat(); /** * The storeTheDead(Rat pRat) method stores the argument Rat in a list of dead rats. * precondition: pRat must reference a Rat object, a list structure of some kind that stores rats, must exist. * postcondition: pRat's reference is added to a list of dead rats. * @param pRat */ publicvoid storeTheDead(RatInterface pRat); /** * The returnTheDead() method retrieves a list of the rats that died in the cell. * @precondition The dead rat ArrayList must exist though it need not have any rats in it. * @postcondition none * @return * ArrayList<> of Rat objects. */ public ArrayList returnTheDead(); }
I need help with this Java program over a Cell class program shown below detailed in the given image:
This is the Java code (Cell class)that need fixed with help of both the given image and the interface guide -
package classPackage;
import java.util.ArrayList;
import interfaces.CellInterface;
import interfaces.RatInterface;
/**
* @author Owner
*
*/
public class Cell implements CellInterface {
privatefinalint [] location;
private ArrayList <RatInterface> ratHouse = new ArrayList <RatInterface>();
public Cell(int[] pLocation) {
location = pLocation.clone();
}
@Override
publicchar getCellType() {
// TODO Auto-generated method stub
return 0;
}
@Override
publicint[] receiveRat(RatInterface pRat) {
pRat.wearDown();
if (Math.random()<.2)
pRat.refresh();
ratHouse.add(pRat);
returnlocation.clone();
}
@Override
public RatInterface retrieveRat() {
/**
* The storeTheDead(Rat pRat) method stores the argument Rat in a list of dead rats.
* precondition: pRat must reference a Rat object, a list structure of some kind that stores rats, must exist.
* postcondition: pRat's reference is added to a list of dead rats.
* @param pRat
*/
returnratHouse;
}
@Override
publicvoid storeTheDead(RatInterface pRat) {
/**
* The returnTheDead() method retrieves a list of the rats that died in the cell.
* @precondition The dead rat ArrayList must exist though it need not have any rats in it.
* @postcondition none
* @return
* ArrayList<> of Rat objects.
*/
}
@Override
public ArrayList<RatInterface> returnTheDead() {
// TODO Auto-generated method stub
returnnull;
}
}
The interface code that has directions that needs to be inputted in the cell class code -
package interfaces;
import java.util.ArrayList;
/**
* @author Owner
*
*/
public interface CellInterface
{
int[] location = newint[2];
/**
* The getCellType() returns the cell type
* @Precondition The cell type must be initialized as a final variable during the construction of a cell object.<br>
* It should indicate one of the four cell types Cell, Hole, Waste, or Shelter
* @Postcondition no change
* @return a character for the cell type
*/
publicchar getCellType();
/**
* The receiveRat() method receives a rat and stores the rat
* @param RatInterface holds reference to Rat object
* @return
* Returns {row,col}<br>
* cell location if rat is accepted and stored<br>
* -1, -1 if there is no space to hold the rat
*
*/
publicint[] receiveRat(RatInterface pRat);
/**
* The retrieveRat(String pRatID) method receives a rat ID and returns the reference to that rat if the rat is stored in the cell
* @param RatID holds String ID of Rat object
* @return Returns the reference to a Rat object if there is one in the cell
*/
public RatInterface retrieveRat();
/**
* The storeTheDead(Rat pRat) method stores the argument Rat in a list of dead rats.
* precondition: pRat must reference a Rat object, a list structure of some kind that stores rats, must exist.
* postcondition: pRat's reference is added to a list of dead rats.
* @param pRat
*/
publicvoid storeTheDead(RatInterface pRat);
/**
* The returnTheDead() method retrieves a list of the rats that died in the cell.
* @precondition The dead rat ArrayList must exist though it need not have any rats in it.
* @postcondition none
* @return
* ArrayList<> of Rat objects.
*/
public ArrayList<RatInterface> returnTheDead();
}
![The Cell class will:
implement CellInterface
store the Cell's location on the grid. Do this during the constructor.
"house" a rat between moves by using receive Rat(Rat) to take the rat and then store it.
randomly wear down or refresh the rat.
hold rats that die in the cell.
return rats that die in the cell.
return a rat when asked, if that one is housed in it.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F4e135d5c-f867-4afd-9f0d-b505f4f19664%2Fc660961c-3286-4682-8afc-528af0e0029b%2Fsp2qclh_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 4 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)