Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

See my work below, I keep getting errors and nothing I do seems to fix it. ** errors I got error: illegal start of expression

See my work below, I keep getting errors and nothing I do seems to fix it.

** errors I got

error: illegal start of expression

public boolean equals(firstScaryMonster secondScaryMonster)

^

54: error: ';' expected

public boolean equals(firstScaryMonster secondScaryMonster)

^

54: error: ';' expected

public boolean equals(firstScaryMonster secondScaryMonster)

^

56: error: illegal character: '\u0003'

if ((this.sethitPoints.equals(secondScaryMonster.sethitPoints)) && ((this.setgoldInPouch ondScaryMonster.setgoldInPouch))

^

56: error: ')' expected

if ((this.sethitPoints.equals(secondScaryMonster.sethitPoints)) && ((this.setgoldInPouch ondScaryMonster.setgoldInPouch))

^

56: error: illegal start of expression

if ((this.sethitPoints.equals(secondScaryMonster.sethitPoints)) && ((this.setgoldInPouch ondScaryMonster.setgoldInPouch))

^

56: error: ';' expected

if ((this.sethitPoints.equals(secondScaryMonster.sethitPoints)) && ((this.setgoldInPouch ondScaryMonster.setgoldInPouch))

^

56: error: variable declaration not allowed here

if ((this.sethitPoints.equals(secondScaryMonster.sethitPoints)) && ((this.setgoldInPouch ondScaryMonster.setgoldInPouch))

^

57: error: ';' expected

(this.monsterName.equals(secondScaryMonster.monsterName)))

^

61: error: 'else' without 'if'

else

^

10 errors

Tool completed with exit code 1

Class questions

In last weeks discussion thread you wrote a class description for some objects. This week you must refine your description by writing two constructors (a default constructor and a constructor with parameters) and an equalsmethod to implement your definition of equality among your objects. Write the constructors and the equals method inside the class you created last week. Write testing code in the Class Driver to test your new constructor and equals method. Show also a screen capture of the driver running your programs.

*** My Driver

import java.util.Scanner;

public class ScaryMonsterDriver

{ //Start ScaryMonsterDriver Class

public static void main (String[]args)

{ // Start Static Void Main

ScaryMonster firstScaryMonster; // This is to declare the first monster

ScaryMonster secondScaryMonster; // This is to declare the second monster

ScaryMonster thirdScaryMonster; // This is to declare the third monster

// Create the Scary Monsters three times

firstScaryMonster = new ScaryMonster();

secondScaryMonster = new ScaryMonster();

thirdScaryMonster = new ScaryMonster();

// Set the monster Name

firstScaryMonster.setmonsterName("Small Hairy Scary Monster");

secondScaryMonster.setmonsterName("Medium Hairy Scary Monster");

thirdScaryMonster.setmonsterName("Large Hairy Scary Monster");

// Set the monster Hitpoints

firstScaryMonster.sethitPoints(100);

secondScaryMonster.sethitPoints(200);

thirdScaryMonster.sethitPoints(300);

// Set the monster currency level

firstScaryMonster.setgoldInPouch(20);

secondScaryMonster.setgoldInPouch(25);

thirdScaryMonster.setgoldInPouch(50);

System.out.println("First monster is a " + firstScaryMonster.getMonsterName()+" with hit points "+firstScaryMonster.gethitPoints()+" and with gold = "+firstScaryMonster.getgoldInPouch()); // prints out monster name, hitpoint and gold

System.out.println("Second monster is a " + secondScaryMonster.getMonsterName()+" with hit points "+secondScaryMonster.gethitPoints()+" and with gold = "+secondScaryMonster.getgoldInPouch()); // prints out monster name, hitpoint and gold

System.out.println("Third monster is a " + thirdScaryMonster.getMonsterName()+" with hit points "+thirdScaryMonster.gethitPoints()+" and with gold = "+thirdScaryMonster.getgoldInPouch()); // prints out monster name, hitpoint and gold

//if (firstScaryMonster.equals(secondScaryMonster))

public boolean equals(firstScaryMonster secondScaryMonster)

{

if ((this.sethitPoints.equals(secondScaryMonster.sethitPoints)) && ((this.setgoldInPouch secondScaryMonster.setgoldInPouch))

(this.monsterName.equals(secondScaryMonster.monsterName)))

{

System.out.println("these monsters are the same");

}

else

{

System.out.println("these monsters are not the same");

}

}

} // End Static Void Main

} //End ScaryMonsterDriver Class

*** My Object

public class ScaryMonster

{ // Start of public class

private String monsterName; // instance variable for name of monster

private int hitPoints; // instance variable to hold the number of hitpoints monster have

private int goldInPouch; // instance veriable to hold how much gold monster has

// Accessor Methods

public String getMonsterName() { // method to return the current MonsterName

return this.monsterName;

}

public int gethitPoints() { // method to return the current number of hitpoints

return this.hitPoints;

}

public int getgoldInPouch() { // method to return the current number of gold in pouch

return this.goldInPouch;

}

// Mutator Methods

public void setmonsterName(String newMonsterName)

{ // method to change monsters anme

this.monsterName = newMonsterName;

}

public void sethitPoints(int HitPoints)

{ // method to change # of legs

this.hitPoints = HitPoints;

}

public void setgoldInPouch(int goldInPouch)

{ // method to change # of legs

this.goldInPouch = goldInPouch;

}

} // End of public class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions