Page 1 of 2 12 LastLast
Results 1 to 20 of 22
  1. #1
    globo is offline Member
    Join Date
    Sep 2010
    Posts
    61
    Rep Power
    0

    Default can't find symbol

    I don't know what what I am doing wrong here.
    This code must be changed.

    Java 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
       }
    }
    This is my code
    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.

    Java 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;
    	}
    
    		
    }
    output
    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

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    globo is offline Member
    Join Date
    Sep 2010
    Posts
    61
    Rep Power
    0

    Default

    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

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by globo View Post
    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.

  5. #5
    globo is offline Member
    Join Date
    Sep 2010
    Posts
    61
    Rep Power
    0

    Default

    So, you are saying I need a contractor in the building class?

  6. #6
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    6

    Wink

    Quote Originally Posted by globo View Post
    So, you are saying I need a contractor in the building class?
    Not a contractor, but a constructor that can take only an int.

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  7. #7
    globo is offline Member
    Join Date
    Sep 2010
    Posts
    61
    Rep Power
    0

    Default

    I am lost here an examples would be great.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by globo View Post
    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?

  9. #9
    Fortu is offline Member
    Join Date
    Dec 2010
    Posts
    57
    Rep Power
    0

    Default

    You have this code:
    Java Code:
    	public Building()
    	{
    	
    		super ();
    	}
    	
    	public Building (String name, int amount)
    	{
    		this.name = name;
    		setPeople(num);
    	}
    And you call

    Java Code:
    new Building(220);
    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.

  10. #10
    globo is offline Member
    Join Date
    Sep 2010
    Posts
    61
    Rep Power
    0

    Default

    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);
       }		
    }

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  12. #12
    globo is offline Member
    Join Date
    Sep 2010
    Posts
    61
    Rep Power
    0

    Default

    TestBuilding.java:7: cannot find symbol
    symbol : constructor Building()
    location: class Building
    Building dentistOffice = new Building(); // default to zero
    ^
    1 error

  13. #13
    globo is offline Member
    Join Date
    Sep 2010
    Posts
    61
    Rep Power
    0

    Default

    It looks like the same thing as before.

  14. #14
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by globo View Post
    It looks like the same thing as before.
    Please post the exact error message. It helps immensely.

  15. #15
    globo is offline Member
    Join Date
    Sep 2010
    Posts
    61
    Rep Power
    0

    Default

    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

  16. #16
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by globo View Post
    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
    This suggests that you've changed your Building class without telling us. Tell me, did you do away with the default constructor, the one what takes no parameters?

  17. #17
    globo is offline Member
    Join Date
    Sep 2010
    Posts
    61
    Rep Power
    0

    Default

    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.

  18. #18
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  19. #19
    globo is offline Member
    Join Date
    Sep 2010
    Posts
    61
    Rep Power
    0

    Default

    I did look at #10 (permalink)

  20. #20
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by globo View Post
    I did look at #10 (permalink)
    Got it. So you've gotten rid of the default constructor for Building, the one that takes no parameters. One possible obvious solution is to add back a default constructor, again one that has an empty parameter list.

Page 1 of 2 12 LastLast

Similar Threads

  1. Cannot find symbol
    By Johanis in forum New To Java
    Replies: 19
    Last Post: 11-04-2010, 09:13 PM
  2. Still cannot find symbol!
    By Johanis in forum New To Java
    Replies: 1
    Last Post: 11-04-2010, 05:32 PM
  3. cannot find symbol
    By GabWit in forum New To Java
    Replies: 3
    Last Post: 01-25-2009, 01:13 AM
  4. Replies: 9
    Last Post: 10-18-2008, 09:26 PM
  5. Replies: 3
    Last Post: 05-01-2008, 09:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •