Question

Can someone tell me why this isnt compiling. The language is java Ive attached my 2...

Can someone tell me why this isnt compiling. The language is java Ive attached my 2 files im getting my one and only error on line 24 of my monster file. the error says:

error cannot find symbol

return weapon.getName

^

File 1. Monster.java

import java.util.Random;

class Monster{
private String name;
private int health;
private Weapon weapon;
  
public Monster(String monsterName, int monsterHealth, Weapon monsterWeapon){
name = monsterName;
health = monsterHealth;
weapon = monsterWeapon;
  
}
  
public String getName(){
return name;
}
  
public int getHealth(){
return health;
}
  
public String getWeaponName(){
return weapon.getName();
}
  
public int attack(Monster other){
Random rand = new Random();
int n = rand.nextInt(weapon.getMaxDamage()) + 1;
return n;
}
}

File 2. Weapon.java

class Weapon{
private String name;
private int maxDamage;
  
public Weapon(){
name = "Pointy Strick";
maxDamage = 2;
}
  
public Weapon(String wname, int wmaxDamage){
name = wname;
maxDamage = wmaxDamage;
}
  
public String gatName(){
return name;
}
  
public void setName(String newName){
name = newName;
}
  
public int getMaxDamage(){
return maxDamage;
}
  
public void setMaxDamage(int newMaxDamage){
maxDamage = newMaxDamage;
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
class Weapon{
    private String name;
    private int maxDamage;

    public Weapon(){
        name = "Pointy Strick";
        maxDamage = 2;
    }

    public Weapon(String wname, int wmaxDamage){
        name = wname;
        maxDamage = wmaxDamage;
    }

    public String getName(){
        return name;
    }

    public void setName(String newName){
        name = newName;
    }

    public int getMaxDamage(){
        return maxDamage;
    }

    public void setMaxDamage(int newMaxDamage){
        maxDamage = newMaxDamage;
    }
}

Add a comment
Know the answer?
Add Answer to:
Can someone tell me why this isnt compiling. The language is java Ive attached my 2...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters...

    Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters and getter methods for the new variable and modify the toString method. The objectstudent program is in this weeks module, you can give it a default value of 19090. class Student { private int id; private String name; public Student() { id = 8; name = "John"; } public int getid() { return id; } public String getname() { return name; } public void...

  • Java. Java is a new programming language I am learning, and so far I am a...

    Java. Java is a new programming language I am learning, and so far I am a bit troubled about it. Hopefully, I can explain it right. For my assignment, we have to create a class called Student with three private attributes of Name (String), Grade (int), and CName(String). In the driver class, I am suppose to have a total of 3 objects of type Student. Also, the user have to input the data. My problem is that I can get...

  • 2 Lab5 - Compatibility Mode - Saved to my Mac View Tell me jout References Mailings...

    2 Lab5 - Compatibility Mode - Saved to my Mac View Tell me jout References Mailings Review A Аа C 21 पा daBbCode AaBbCcDc AaBbCcDe AaBb CcD ABCDdF Emphasis Heading 1 Heading 2 Heading Heading ANA- Objectives: In this lab, the following topics will be covered 1. Inheritance in Java), 2. Overriding, and Hiding Inheritance (in Java): Inheritance is an important object-oriented concept that allows classes to be reused in order to define similar, but distinct, classes. In this lab...

  • The FoodItem.java file defines a class called FoodItem that contains instance variables for name (String) and...

    The FoodItem.java file defines a class called FoodItem that contains instance variables for name (String) and calories (int), along with get/set methods for both. Implement the methods in the Meal class found in Meal.java public class FoodItem{ private String name; private int calories;    public FoodItem(String iName, int iCals){ name = iName; calories = iCals; }    public void setName(String newName){ name = newName; }    public void setCalories(int newCals){ calories = newCals; }    public int getCalories(){ return calories;...

  • Required in Java. Thank you. 1. Create a base class called Vehicle that has the manufacturer's...

    Required in Java. Thank you. 1. Create a base class called Vehicle that has the manufacturer's name (type String), number of cylinders in the engine (type int), and owner (type Person given in Listing 8.1 in the textbook and in LMS). Then create a class called Truck that is derived from Vehicle and has additional properties: the load capacity in tons (type double, since it may contain a fractional part) and towing capacity in tons (type double). Give your classes...

  • public class Item implements Comparable { private String name; private double price; /** * Constructor for...

    public class Item implements Comparable { private String name; private double price; /** * Constructor for objects of class Item * @param theName name of item * @param thePrice price of item */ public Item(String theName, double thePrice) { name = theName; price = thePrice; }    /** * gets the name * @return name name of item */ public String getName() { return name; }    /** * gets price of item * @return price price of item */...

  • Write in java and the class need to use give in the end copy it is...

    Write in java and the class need to use give in the end copy it is fine. Problem Use the Plant, Tree, Flower and Vegetable classes you have already created. Add an equals method to Plant, Tree and Flower only (see #2 below and the code at the end). The equals method in Plant will check the name. In Tree it will test name (use the parent equals), and the height. In Flower it will check name and color. In...

  • In Java, Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following...

    In Java, Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following additional attributes: how many people are served every year and the average price per person. code the constructor, accessors, mutators, toString and equals method of the new subclass; also code a method returning the average taxes per year. You also need to include a client class to test your code for both the parent class and the subclass. Code for Store below(Super class aka...

  • I need help with my code. It keeps getting this error: The assignment is: Create a...

    I need help with my code. It keeps getting this error: The assignment is: Create a class to represent a Food object. Use the description provided below in UML. Food name : String calories : int Food(String, int) // The only constructor. Food name and calories must be // specified setName(String) : void // Sets the name of the Food getName() : String // Returns the name of the Food setCalories(int) : void // Sets the calories of the Food...

  • import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {   ...

    import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {        Student s1 = new Student();         Student s2 = new Student("Smith", "123-45-6789", 3.2);         Student s3 = new Student("Jones", "987-65-4321", 3.7);         System.out.println("The name of student #1 is ");         System.out.println("The social security number of student #1 is " + s1.toString());         System.out.println("Student #2 is " + s2);         System.out.println("the name of student #3 is " + s3.getName());         System.out.println("The social security number...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT