Results 1 to 20 of 22
Thread: can't find symbol
- 01-16-2011, 06:42 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 61
- Rep Power
- 0
can't find symbol
I don't know what what I am doing wrong here.
This code must be changed.
This is my codeJava Code:public class TestBuilding { public static void main(String [] args) { Building school = new Building(220); // 220 people in school Building starbucks = new Building(37); Building dentistOffice = new Building(); // default to zero // acceessor System.out.println("School: " + school.getPeople() ); // mutator starbucks.setPeople(40); school.setPeople(221); System.out.println("School: " + school.getPeople()); System.out.println("Starbucks: " + starbucks.getPeople()); System.out.println("Dentist: " + dentistOffice.getPeople()); // toString System.out.println("Print school, again, but with toString:"); System.out.println( school.toString() ); // explicit toString System.out.println( school ); // implicit toString } }
I don't know what I am doing wrong I am trying to get the this to compile wit the previous code and generate this output.
outputJava Code:class Building { public static int DEFAULT_People= 0; int num; private String name; public Building() { super (); } public Building (String name, int amount) { this.name = name; setPeople(num); } public void setPeople (int amount) { if (num >= 0 ) num = amount; else num = DEFAULT_People; } public void more(int amount) { if (num >= 0) amount += num; } public int getPeople() { return num; } @Override public String toString() { return "School" + num; } }
School: 220
School: 221
Starbucks: 40
Dentist: 0
Print school, again, but with toString:
Number of people is this building is 221
Number of people is this building is 221
-
Can you show the actual error message and indicate which lines cause the error?
- 01-16-2011, 06:52 PM #3
Member
- Join Date
- Sep 2010
- Posts
- 61
- Rep Power
- 0
My code compiles fine.
But when I compile the source code / Test Building I receive this error.
TestBuilding.java:5: cannot find symbol
symbol : constructor Building(int)
location: class Building
Building school = new Building(220); // 220 people in school
^
TestBuilding.java:6: cannot find symbol
symbol : constructor Building(int)
location: class Building
Building starbucks = new Building(37);
^
2 errors
-
As is usual, the error is telling exactly what's wrong. You're calling the Building constructor and passing an int to it. Does your Building class have such a constructor? You will get better at understanding error messages with practice, so I recommend you keep looking at them closely and try to understand them.
Luck.
- 01-16-2011, 06:55 PM #5
Member
- Join Date
- Sep 2010
- Posts
- 61
- Rep Power
- 0
So, you are saying I need a contractor in the building class?
- 01-16-2011, 07:00 PM #6
- 01-16-2011, 07:02 PM #7
Member
- Join Date
- Sep 2010
- Posts
- 61
- Rep Power
- 0
I am lost here an examples would be great.
-
What's confusing? You're calling new Building(220) and have no constructor that just takes one parameter, an int. So you either need to change your new Building calls and instead make them that use Building constructors that are available (either no parameter, or two parameters, one String and one int) or you need to create a new Building constructor that just takes one parameter, an int.
What about this don't you understand?
- 01-16-2011, 08:34 PM #9
Member
- Join Date
- Dec 2010
- Posts
- 57
- Rep Power
- 0
You have this code:
And you callJava Code:public Building() { super (); } public Building (String name, int amount) { this.name = name; setPeople(num); }
You don't have a constructor in your Building class that only takes an int value. You have one that takes nothing, and one that takes an int and a String object.Java Code:new Building(220);
- 01-16-2011, 10:31 PM #10
Member
- Join Date
- Sep 2010
- Posts
- 61
- Rep Power
- 0
This is my code.
I got everything to work
except for the Dentist: 0.
It give me this error
symbol : constructor Building()
location: class Building
Building dentistOffice = new Building(); // default to zero
^
1 error
Java Code:class Building //extends TestBuilding { int DEFAULT_people = 0; int num; public Building(int people) { super (); setPeople(people); if (num >=0 ) num = people; } public void setPeople (int people) { if (num >= 0 ) num = people; else num = DEFAULT_people; } public void enter (int people) { if (num >= 0) people += num; } public int getPeople() { return num; } public String toString() { return String.format("Number of people in this building is %d", num); } }
-
- 01-16-2011, 10:33 PM #12
Member
- Join Date
- Sep 2010
- Posts
- 61
- Rep Power
- 0
TestBuilding.java:7: cannot find symbol
symbol : constructor Building()
location: class Building
Building dentistOffice = new Building(); // default to zero
^
1 error
- 01-16-2011, 10:34 PM #13
Member
- Join Date
- Sep 2010
- Posts
- 61
- Rep Power
- 0
It looks like the same thing as before.
-
- 01-16-2011, 10:37 PM #15
Member
- Join Date
- Sep 2010
- Posts
- 61
- Rep Power
- 0
See when I compile TestBuilding because it's the one that the main.. I get this error
TestBuilding.java:7: cannot find symbol
symbol : constructor Building()
location: class Building
Building dentistOffice = new Building(); // default to zero
^
1 error
-
- 01-16-2011, 10:55 PM #17
Member
- Join Date
- Sep 2010
- Posts
- 61
- Rep Power
- 0
Look I need to call this line so it report 0.
//Building dentistOffice = new Building(); // default to zero
But it is associated with this line too:
System.out.println("Dentist: " + dentistOffice.getPeople());
based on the last coded I submitted when i comment out these two line I have this
output
School: 220
School: 221
Starbucks: 40
Print school, again, but with toString:
Number of people in this building is 221
Number of people in this building is 221
Which means I only have one error now is to get this Dentist: 0 to appear.
-
Please post your most recent code for the Building class.
- 01-16-2011, 11:10 PM #19
Member
- Join Date
- Sep 2010
- Posts
- 61
- Rep Power
- 0
I did look at #10 (permalink)
-
Similar Threads
-
Cannot find symbol
By Johanis in forum New To JavaReplies: 19Last Post: 11-04-2010, 08:13 PM -
Still cannot find symbol!
By Johanis in forum New To JavaReplies: 1Last Post: 11-04-2010, 04:32 PM -
cannot find symbol
By GabWit in forum New To JavaReplies: 3Last Post: 01-25-2009, 12:13 AM -
cannot find symbol symbol :constructor Error. Please help! =(
By KalEl in forum New To JavaReplies: 9Last Post: 10-18-2008, 08: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, 08:30 AM


LinkBack URL
About LinkBacks
Reply With Quote
.gif)

Bookmarks