Results 1 to 6 of 6
Thread: Cannot find symbol class
- 06-06-2011, 09:13 AM #1
Member
- Join Date
- Jun 2011
- Posts
- 6
- Rep Power
- 0
Cannot find symbol class
I wrote a new class called Pet and I'm trying to get it connected to a pre-written class called Assignment4 for, well, an assignment. However, I can't link the two together. They're saved in the same folder on my computer, so I don't understand the problem. I get the error "cannot find symbol constructor Pet()". Here is the complete code. Thanks in advance for any help.
First Program
Java Code:public class Pet { private static String petName; private static String type; private static BirthInfo birth; public Pet(String petName, String type) { petName = "?"; type = "?"; } public String getPetName() { return petName; } public String getType() { return type; } public BirthInfo getBirthInfo() { return birth; } public void setPetName (String pName) { petName = pName; } public void setType (String pType) { type = pType; } public void setBirthInfo(int date, int month, int year, String place) { birth.setDate(date); birth.setMonth(month); birth.setYear(year); birth.setPlace(place); } public String toString() { return "\nPet Name:\t\t" + petName + "\nType:\t\t\t" + type + "\nBirth Information:\t" + birth + "\n\n"; } }
Java Code:import java.io.*; //to use InputStreamReader and BufferedReader import java.util.*; public class Assignment4 { public static void main (String[] args) { // local variables, can be accessed anywhere from the main method char input1 = 'Z'; String inputInfo; String name, type, place; int date, month, year; String line = new String(); // instantiate a Pet object Pet pet1 = new Pet(); printMenu(); //Create a Scanner object to read user input Scanner scan = new Scanner(System.in); do // will ask for user input { System.out.println("What action would you like to perform?"); line = scan.nextLine(); if (line.length() == 1) { input1 = line.charAt(0); input1 = Character.toUpperCase(input1); // matches one of the case statement switch (input1) { case 'A': //Add Pet System.out.print("Please enter the pet information:\n"); System.out.print("Enter a pet name:\n"); name = scan.nextLine(); pet1.setPetName(name); System.out.print("Enter its type:\n"); type = scan.nextLine(); pet1.setType(type); System.out.print("Enter its birth date:\n"); date = Integer.parseInt(scan.nextLine()); System.out.print("Enter its birth month:\n"); month = Integer.parseInt(scan.nextLine()); System.out.print("Enter its birth year:\n"); year = Integer.parseInt(scan.nextLine()); System.out.print("Enter its birth place:\n"); place = scan.nextLine(); pet1.setBirthInfo(date, month, year, place); break; case 'D': //Display Pet System.out.print(pet1); break; case 'Q': //Quit break; case '?': //Display Menu printMenu(); break; default: System.out.print("Unknown action\n"); break; } } else { System.out.print("Unknown action\n"); } } while (input1 != 'Q' || line.length() != 1); } /** The method printMenu displays the menu to a user **/ public static void printMenu() { System.out.print("Choice\t\tAction\n" + "------\t\t------\n" + "A\t\tAdd Pet\n" + "D\t\tDisplay Pet\n" + "Q\t\tQuit\n" + "?\t\tDisplay Help\n\n"); } }
- 06-06-2011, 09:17 AM #2
Read teh error message very carefully. How many parameters does your Pet constructor expect? How many parameters are you passing it?
- 06-06-2011, 09:18 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
"cannot find symbol constructor Pet()"
- 06-06-2011, 09:25 AM #4
Member
- Join Date
- Jun 2011
- Posts
- 6
- Rep Power
- 0
Ah yes, not sure why I added those arguments in there. I took them out and everything seems to be working fine. Thank you!
- 06-06-2011, 09:27 AM #5
In future please try to read and comprehend what the error message says. This one was relatively easy to understand.
- 06-06-2011, 09:29 AM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
Similar Threads
-
Cannot find symbol class, but why not?
By gnng in forum New To JavaReplies: 3Last Post: 04-01-2011, 04:57 PM -
Extended Class - Cannot Find Symbol
By javak in forum New To JavaReplies: 15Last Post: 02-27-2011, 05:43 PM -
cannot find symbol symbol :constructor Error. Please help! =(
By KalEl in forum New To JavaReplies: 9Last Post: 10-18-2008, 09:26 PM -
cannot find symbol symbol : class Item location: package platypos.services.order
By officialhopsof in forum New To JavaReplies: 3Last Post: 05-01-2008, 09:30 AM -
cannot find symbol class error
By po0oker in forum New To JavaReplies: 5Last Post: 10-31-2007, 03:52 PM
Bookmarks