Question: Java Reference code for PieceScooby /** * PieceScooby class */ public class PieceScooby { private String symbol; private int numScoobySnacks; private boolean hidden; private boolean

Java

Java Reference code for PieceScooby /** * PieceScooby class */ public class

Reference code for PieceScooby

/** * PieceScooby class */ public class PieceScooby { private String symbol; private int numScoobySnacks; private boolean hidden; private boolean canMove; private boolean original; /** * @param symbol * @param numScoobySnacks * @param hidden * @param canMove * @param original */ public PieceScooby(String symbol, int numScoobySnacks, boolean hidden, boolean canMove, boolean original) { this.symbol = symbol; this.numScoobySnacks = numScoobySnacks; this.hidden = hidden; this.canMove = canMove; this.original = original; } /** * Default constructor */ public PieceScooby() { this.symbol = "S"; this.numScoobySnacks = 0; this.hidden = false; this.canMove = true; this.original = true; } /** * @return the symbol */ public String getSymbol() { return symbol; } /** * @return the numScoobySnacks */ public int getNumScoobySnacks() { return numScoobySnacks; } /** * @return the hidden */ public boolean isHidden() { return hidden; } /** * @return the canMove */ public boolean isEntangled() { if (!canMove) { entangle(); } return canMove; } /** * @return the original */ public boolean canSpawn() { return original; } /** * @param symbol the symbol to set */ public void setSymbol(String symbol) { this.symbol = symbol; } /** * @param hidden the hidden to set */ public void setHidden(boolean hidden) { this.hidden = hidden; } /** * set the original to false */ public void entangle() { this.original = false; } /** * display the message */ public void speak() { System.out.println("Scooby-Dooby-Doo!"); } /** * eatScoobySnack method */ private void eatScoobySnack() { // if the number of Scooby Snacks is greater than 0 if (numScoobySnacks > 0) { // decreases the number by 1 numScoobySnacks -= 1; // canMove propoerty is set true canMove = true; } } /** * @param num */ public void collectScoobySnacks(int num) { // not negative if (num > 0) { // increases the number by 1 numScoobySnacks += 1; // call eatScoobySnack method eatScoobySnack(); } } }

C) [10 points] Write a public method in your PieceScooby class called spawn with no parameters and returns a NEW PieceScooby with: scooby snacks and canMove properties should have same values as object that this method is being called on (this) hidden and original properties should be set to false symbol should be set to the symbol of the object that this method is being called on (this) with the value 'C' concatenated to the end of it. public PieceScooby spawn()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!