I have been working on this code for days now and I am down to one error:error: class, interface, or enum expected showing at line 56, I have no idea why it won't work... any suggestions? thanks!

import java.util.*;

public class Pet 
{


        // This gives the user a field to store the name in
        private String name;
        private String type;
        private double age;

      public Pet(String n, String t, double a);
      {
         name = n;
         type = t;
         age = a;
      }
    public void setName(string n);
    {
        name = n;
    }
    public void setType(String t);
    {
        type = t;
    }
    public void setType(double a);
    {
        age = a;
    }
    public String getName();
    {
        return name;
    }
    public String getType();
    {
        return type;
    }
    public double getAge();
    {
        return age;
    }

}
        import java.util.*;

public class PetTest
 {
    public static void main(String[] args);
    {
        String testN; // test name
        String testT; //test type
        double testA; // test age


        Scanner keyboard = new Scanner(System.in);

        // get pets name
        System.out.print("Enter your pets name: ");
        testN= keyboard.nextDouble();
        // get pets age
        system.out.print("Enter your pets age: ");
        testA= keyboard.nextLine();
        // get type of pet
        system.out.print("Enter the type of pet you have: ");
        testT= keyboard.nextLine();

        //pass information received to the original pet class
        Pet pet= new Pet(testN, testT, testA);

        //display the output
        System.out.println();
        System.out.println("Here is the information your have provided: ");
        System.out.println("Name:  " + pet.getName());
        System.out.println("Type:  " + pet.getType());
        System.out.println("Age:  " + pet.getAge());

 }
}

Double check your use of semicolons. You have a bunch of them where they shouldn't be.

Even when they are gone it is still causing the same error

Even when they are gone it is still causing the same error

Where did you remove them? One example of an incorrect semicolon is here:

public static void main(String[] args);

You don't terminate the signature of a function definition with a semicolon.

my code is now :

 import java.util.*;

public class Pet 
{


        // This gives the user a field to store the name in
        private String name;
        private String type;
        private double age;

      public Pet(String n, String t, double a)
      {
         name = n;
         type = t;
         age = a;
      }
    public void setName(string n)
    {
        name = n;
    }
    public void setType(String t)
    {
        type = t;
    }
    public void setType(double a)
    {
        age = a;
    }
    public String getName()
    {
        return name;
    }
    public String getType()
    {
        return type;
    }
    public double getAge()
    {
        return age;
    }

}
        import java.util.*;

public class PetTest
 {
    public static void main(String[] args)
    {
        String testN; // test name
        String testT; //test type
        double testA; // test age


        Scanner keyboard = new Scanner(System.in);

        // get pets name
        System.out.print("Enter your pets name: ");
        testN= keyboard.nextDouble();
        // get pets age
        system.out.print("Enter your pets age: ");
        testA= keyboard.nextLine();
        // get type of pet
        system.out.print("Enter the type of pet you have: ");
        testT= keyboard.nextLine();

        //pass information received to the original pet class
        Pet pet= new Pet(testN, testT, testA);

        //display the output
        System.out.println();
        System.out.println("Here is the information your have provided: ");
        System.out.println("Name:  " + pet.getName());
        System.out.println("Type:  " + pet.getType());
        System.out.println("Age:  " + pet.getAge());

 }
}

You have an import statement just before PetTest, remove it. Actually, if you want both classes to be public then you need to split them into two files and the import statement can remain at the top of the file for PetTest.

I tried this, but it now opens up another bag of worms... im sorry im three weeks into my course on java and it just makes no sense to me... it says 6 errors:

E:\Pet\src\Pet.java:56: error: class PetTest is public, should be declared in a file named PetTest.java
public class PetTest
       ^
E:\Pet\src\Pet.java:28: error: cannot find symbol
    public void setName(string n)
                        ^
  symbol:   class string
  location: class Pet
E:\Pet\src\Pet.java:69: error: incompatible types
        testN= keyboard.nextDouble();
                                  ^
  required: String
  found:    double
E:\Pet\src\Pet.java:71: error: package system does not exist
        system.out.print("Enter your pets age: ");
              ^
E:\Pet\src\Pet.java:72: error: incompatible types
        testA= keyboard.nextLine();
                                ^
  required: double
  found:    String
E:\Pet\src\Pet.java:74: error: package system does not exist
        system.out.print("Enter the type of pet you have: ");
              ^
6 errors

Process completed.
commented: Did you engage your brain *at all*? +0

im sorry im three weeks into my course on java

At this point you should know that Java is a case sensitive language. I kind of assumed you weren't so helpless that I'd have to point it out.

Read the errors and try to understand them. If you don't learn how to debug, you'll fall into a frustrating death spiral that will result in quitting programming.

wow i feel dumb, thank you very much for your time... my last question is how do i fix the error that says "E:\Pet\src\Pet.java:56: error: class PetTest is public, should be declared in a file named PetTest.java
public class PetTest"

how do i fix the error that says "E:\Pet\src\Pet.java:56: error: class PetTest is public, should be declared in a file named PetTest.java public class PetTest"

That's what I was talking about with my addendum that if both classes must be public, they should be split across two files (just like the error says).

thank you so much for your help!! sorry that i kept bothering you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.