6 Replies - 413 Views - Last Post: 26 May 2010 - 04:12 PM Rate Topic: -----

#1 johnathanc456  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 53
  • Joined: 05-May 10

problems compiling

Posted 25 May 2010 - 09:49 PM

Im having some compilation problems and cant seem to see where they are coming from. the main jist of this code is described in the comments.

any suggestions as to what is causing this or any other problems with my code are appreciated.


 public class Building extends java.lang.Object
{//describes a school building. A building object that has a name and holds an array of clasroom objects.
	public String buildingName;
	public int NumClassrooms;
	public Classroom[] classroom;
	
	
		//CONSTRUCTOR
		public Building (int iNumClassrooms, java.lang.String name); 
		{//initializes a Building Object by creating an "array" object that will hold 
			NumClassrooms = iNumClassrooms;
			classroom = new Classroom[NumClassrooms];
			buildingName = name;
		
		}
	
	
		public Classroom addClassroom(java.lang.String label, int iWhiteboards, int iSeats)
		{//if the building has room for another classroom object:
			
			//creates a classroom object with the specified label, number of wwhiteboards and number of seats.
			Whiteboards = iWhiteboards;
			Seats = iSeats;
			
			//adds this classroom object to the array of classrooms.
			
			//returns a pointer to the new Classroom object.
			return 0;
		
		}
		
		public int maximumCapacity()
		{//returns the total number of seats in the building
		 //the total number of seats is the sum of the number of seats in each classroom in the building at the time maxcapacity is called.
		 //Loop over all the valid classroom objects stored in the building array
		 //call each classroom objects getSeats() method and add the # returned to the total.
		 
		
		
			return 0;
		}
		
		public Classroom find(java.lang.String searchFor)
		{//searches the building for the first classroom having a label with the same characters as the string passed in.
			
			//returns the pointer to the first Classroom ovject whos label matches searchFor
			//returns null if non of the classrooms in the building have a matchng label.
			return false;
		}
	
}





Is This A Good Question/Topic? 0
  • +

Replies To: problems compiling

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10468
  • View blog
  • Posts: 38,799
  • Joined: 27-December 08

Re: problems compiling

Posted 25 May 2010 - 09:51 PM

Can you specifically describe the errors you are encountering?
Was This Post Helpful? 0
  • +
  • -

#3 m-e-g-a-z  Icon User is offline

  • Winning
  • member icon


Reputation: 496
  • View blog
  • Posts: 1,453
  • Joined: 19-October 09

Re: problems compiling

Posted 25 May 2010 - 09:56 PM

The following method

public Classroom addClassroom(java.lang.String label, int iWhiteboards, int iSeats)

Is meant to return a Classroom object, but you return an Integer 0 - Giving you a mismatch exception.

Another method which has the wrong return type, it returns a boolean but the method is meant to return a Classroom object.
public Classroom find(java.lang.String searchFor)


Also what is this

java.lang.String

wouldnt it be easier using String
Was This Post Helpful? 0
  • +
  • -

#4 johnathanc456  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 53
  • Joined: 05-May 10

Re: problems compiling

Posted 25 May 2010 - 10:03 PM

yes, below is the compile errors that i am getting. the only thing i can think of is that the constructor isn't correct but, to me it looks fine....

Building.java:17: missing method body, or declare abstract
		public Building (int iNumClassrooms, java.lang.String name); 
		       ^
Building.java:19: cannot find symbol
symbol  : variable iNumClassrooms
location: class Building
			NumClassrooms = iNumClassrooms;
			                ^
Building.java:21: cannot find symbol
symbol  : variable name
location: class Building
			buildingName = name;
			               ^
Building.java:30: cannot find symbol
symbol  : variable Whiteboards
location: class Building
			Whiteboards = iWhiteboards;
			^
Building.java:31: cannot find symbol
symbol  : variable Seats
location: class Building
			Seats = iSeats;
			^
Building.java:36: incompatible types
found   : int
required: Classroom
			return 0;
			       ^
Building.java:56: incompatible types
found   : boolean
required: Classroom
			return false;
			       ^
7 errors




@ m-e-g-a-z thanks for the feedback ill try to change some of those and see how it works out.
Was This Post Helpful? 0
  • +
  • -

#5 johnathanc456  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 53
  • Joined: 05-May 10

Re: problems compiling

Posted 25 May 2010 - 10:11 PM

it is still giving me most of the same errors
Was This Post Helpful? 0
  • +
  • -

#6 m-e-g-a-z  Icon User is offline

  • Winning
  • member icon


Reputation: 496
  • View blog
  • Posts: 1,453
  • Joined: 19-October 09

Re: problems compiling

Posted 26 May 2010 - 04:51 AM

Even if the constructor was fine, you are missing alot of things.

I cant see where you have initialised your variables such as 'Seats','Whiteboards'...

Initialise them just like you did for the variable 'buildingName'.

Also, it is good practice to follow naming conventions when creating your Variables.

int seats;
int whiteboards;
//...



whiteboards = iWhiteboards;
seats = iSeats;



I would also advise you to use a dynamic data structure such as an ArrayList to hold your Classroom Objects, because i can see you have an addClassroom method. By using Arrays, you are limited to the amount of Classroom object you can store, whereas arraylists can resize.

And last but not least, please read about Methods, it is very important that you try to understand how they work especially return types.

Post the updated code in this thread once you have made the following changes


:)
Was This Post Helpful? 0
  • +
  • -

#7 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10468
  • View blog
  • Posts: 38,799
  • Joined: 27-December 08

Re: problems compiling

Posted 26 May 2010 - 04:12 PM

One problem that is giving you a bunch of errors is your semi-colon at the end of the parenthesis. Only method headers declared abstract can end with a semi-colon.
public Building (int iNumClassrooms, java.lang.String name); // <--- remove the semi-colon



For the addClassroom() method, I'm guessing you need to create a Classroom Object, which has a constructor to accept the params passed to the addClassroom() method. From there, you probably need to add it to the array, then return the new Classroom object, not 0, which is an int, not a Classroom.

Same thing for your find() method. You need to loop through your Classroom[], and return the appropriate Classroom object based on the String passed to teh find() method.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1