javagetter-settercannot-find-symbol

Why is the compiler saying "cannot find symbol" to the getter methods?


When I try to compile the code, it keeps saying "cannot find symbol" every single time I try to call a getter method. I'd love any and all suggestions as to how to fix the problem.

Here is the code with the main method

import java.util.Scanner;

public class Assignment10
{
  public static void main(String [] args)
  {
    Scanner in = new Scanner(System.in);
    System.out.println("\nThis program displays some attributes and behaviors of two different dogs.");
    
    //Create two Dogs objects
    Dogs firstDog = new Dogs();
    Dogs secondDog = new Dogs();
    
    //Naming scheme for first dog
    System.out.print("\nWhat would you like to name the first dog? ");
    firstDog.setName(in.nextLine());
    
    //Naming scheme for second dog
    System.out.print("What would you like to name the second dog? ");
    secondDog.setName(in.nextLine());
    
    //Scheme for getting the breed of first dog
    System.out.print("\nWhat is the breed of the first dog? ");
    firstDog.setBreed(in.nextLine());
    
    //Scheme for getting the breed of first dog
    System.out.print("What is the breed of the second dog? ");
    secondDog.setBreed(in.nextLine());
    
    //Scheme to get age of first dog
    System.out.println("\nWhere is the first dog in their lifespan? ");
    System.out.print("Enter 1 for puppy, 2 for adolescent, 3 for adult, 4 for senior: ");
    firstDog.setAge(in.nextInt());

    //Scheme to get age of second dog
    System.out.println("Where is the first dog in their lifespan? ");
    secondDog.setAge(in.nextInt());
    
    //Scheme to get weight of first dog
    System.out.println("\nWhere is the first dog in the weight range?");
    System.out.print("Enter 1 for low, 2 for medium, 3 for high: ");
    firstDog.setWeight(in.nextInt());
    
    //Scheme to get weight of second dog
    System.out.println("Where is the second dog in the weight range?: ");
    secondDog.setWeight(in.nextInt());
    
    System.out.println("\nThank you for your input.");
    System.out.println("The following describes the first dog:\n");
    
    //Displaying the attributes and behaviors of the first dog
    System.out.println( firstDog.getName + " is a " + firstDog.getAge + " month old " + firstDog.getWeight + " pound " + firstDog.getGender + " " + firstDog.getBreed + " who " + firstDog.getFleas + "fleas.");
    
    System.out.print("When their owner tossed over a doggie treat, " + firstDog.getName + " jumped in the air and went ");
    firstDog.eating();
    System.out.println();
    
    System.out.print("When " + firstDog.getName + " ran back to their owner after fetching the ball, the " + firstDog.getBreed + " dropped the ball and elatedly went ");
    firstDog.barking();
    System.out.println();
    
    if ( firstDog.getFleas().equals("has") )
    {
        System.out.print("After rolling around in the mud, " + firstDog.getName + " always goes ");
        firstDog.scratchingFleas();
    }
    
    //Displaying the attributes and behaviors of the second dog
    System.out.println( secondDog.getName + " is a " + secondDog.getAge + " month old " + secondDog.getWeight + " pound " + secondDog.getGender + " " + secondDog.getBreed + " who " + secondDog.getFleas + "fleas.");
    
    System.out.print( secondDog.getName + " loudly goes ");
    secondDog.eating();
    System.out.println(" whenever they eat.");
    
    System.out.print( secondDog.getName + " goes ");
    secondDog.barking();
    System.out.println(" each and every time there's a squirrel in the backyard.");
    
    if ( secondDog.getFleas().equals("has") )
    {
        System.out.print("The owners brought the " + secondDog.getBreed + " to the vet because " + secondDog.getName + " kept going ");
        secondDog.scratchingFleas();
        System.out.print(" as if there were fleas.");
    }
}

}

and here is the code with the class that defines the objects

public class Dogs
{
    private StringBuffer z = new StringBuffer("");
    private StringBuffer name;
    private StringBuffer breed;
    private String gender;
    private int age;
    private double weight;
    private String fleas;
    private int i = (int)(Math.random() * 20);
    private int j = (int)(Math.random() * 20);
    private int k = (int)(Math.random() * 50);
    private int l = (int)(Math.random() * 50);

    public Dogs()
    {
        name = z;
        breed = z;
        gender = (i <= j) ? "female" : "male";
        age = 0;
        weight = 0;
        fleas = (k <= l) ? "has " : "does not have ";
    }

    public void setName(String s) {
        name = name.append(s);
    }

    public void setBreed(String s) {
        breed = breed.append(s);
    }

    public void setAge(int i)
    {
        if (i == 1)
            age = (int)(1 + Math.random() * 7);
    
        if (i == 2)
            age = (int)(8 + Math.random() * 10);
    
        if (i == 3)
            age = (int)(18 + Math.random() * 66);
    
        if (i == 4)
            age = (int)(84 + Math.random() * 49);
    }

    public void setWeight(int i)
    {
        if (i == 1)
            weight = 10 + Math.random() * 30;
    
        if (i == 2)
            weight = 40 + Math.random() * 60;
        
        if (i == 3)
            weight = 100 + Math.random() * 50;
    }

    public String getName() {
        return name.toString();
    }

    public int getAge() {
        return age;
    }
  
    public double getWeight() {
        return weight;
    }

    public String getGender() {
        return gender;
    }

    public String getBreed() {
        return breed.toString();
    }

    public String getFleas() {
        return fleas;
    }

    public void eating() {
        System.out.print("chomp chomp chomp!");
    }

    public void barking() {
        System.out.print("woof woof woof!");
    }

    public void scratchingFleas() {
        System.out.print("scrhh scrhh scrhh");
    }
}

I really appreciate everyone who helps!!!!


Solution

  • You are not calling the getters. You do dog.getNamewhen you should be doing dog.getName();