Results 1 to 19 of 19
Thread: array help!
- 11-14-2010, 03:16 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 8
- Rep Power
- 0
array help!
i dunno why i keep receiving cannot find symbol in the command prompt.. =( i could not compile because of the one in bold...
here is my codes.. can help me find out if got anything wrong with it?
private ArrayList<Library> librianList;
private ArrayList<OpeningHours> L1Hrs;
private ArrayList<OpeningHours> L2Hrs;
public LibrianManager() {
librianList = new ArrayList<Library>();
L1Hrs = new ArrayList<OpeningHours>();
L2Hrs = new ArrayList<OpeningHours>();
ConsultationHours L1First = new ConsultationHours("Monday", 9, 15);
ConsultationHours L1Second = new ConsultationHours("Friday", 8, 20);
L1Hrs.add(L1First); //add the 2 days to the librian1 array
L1Hrs.add(L1Second);
ConsultationHours L2First = new ConsultationHours("Tuesday", 4, 20);
L2Hrs.add(L2First);
//add to librianList
Library librian1 = new Library("L1", "Mary Anderson", L1Hrs, 40);
Library librian2 = new Library("L2", "Johnny Dept", L2Hrs, 40);
librianList.add(librian1);
librianList.add(librian2);
}
please help! thanks!
- 11-14-2010, 03:21 AM #2
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
can you post your constructors for Library Class
- 11-14-2010, 03:33 AM #3
Member
- Join Date
- Nov 2010
- Posts
- 8
- Rep Power
- 0
ok here it is:
public class Library{
private String id;
private String name;
private WorkingHours workingHours;
private int hourRate;
public Doctor(String dID, String pName, WorkingHours wrkHrs, int hrRate){
id = dID;
name = pName;
workingHours = wrkHrs;
hourRate = hrRate;
}
public String getID(){
return id;
}
public String getName(){
return name;
}
public WorkingHours getWrkHrs(){
return workingHours;
}
public int getHourRate(){
return hourRate;
}
- 11-14-2010, 03:41 AM #4
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
Your Library Constructor is looking for a WorkingHours Object and you are sending it a ConsultationHours object
- 11-14-2010, 04:18 AM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Isn't it being sent an ArrayList of OpeningHours?
Either way you must send a WorkingHours instance.
- 11-14-2010, 04:23 AM #6
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
yup you are right pbrockway2 it is an arraylist I made a mistake between the arraylist L1Hrs and the object L1First etc... its late :)
- 11-14-2010, 07:55 AM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
- 11-14-2010, 09:33 AM #8
Member
- Join Date
- Nov 2010
- Posts
- 8
- Rep Power
- 0
oops. sorry.. i m being careless.
yup! i corrected both mistakes already.. but still can't..
private ArrayList<Library> librianList;
private ArrayList<OpeningHours> L1Hrs;
private ArrayList<OpeningHours> L2Hrs;
public LibrianManager() {
librianList = new ArrayList<Library>();
L1Hrs = new ArrayList<OpeningHours>();
L2Hrs = new ArrayList<OpeningHours>();
OpeningHours L1First = new OpeningHours("Monday", 9, 15);
OpeningHours L1Second = new OpeningHours("Friday", 8, 20);
L1Hrs.add(L1First); //add the 2 days to the librian1 array
L1Hrs.add(L1Second);
OpeningHours L2First = new OpeningHours("Tuesday", 4, 20);
L2Hrs.add(L2First);
//add to librianList
Library librian1 = new Library("L1", "Mary Anderson", L1Hrs, 40);
Library librian2 = new Library("L2", "Johnny Dept", L2Hrs, 40);
librianList.add(librian1);
librianList.add(librian2);
}
public class Library{
private String id;
private String name;
private OpeningHours workingHours;
private int hourRate;
public Library(String dID, String pName, OpeningHours wrkHrs, int hrRate){
id = dID;
name = pName;
workingHours = wrkHrs;
hourRate = hrRate;
}
public String getID(){
return id;
}
public String getName(){
return name;
}
public OpeningHours getWrkHrs(){
return workingHours;
}
public int getHourRate(){
return hourRate;
}
- 11-14-2010, 09:37 AM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 11-14-2010, 09:47 AM #10
Member
- Join Date
- Nov 2010
- Posts
- 8
- Rep Power
- 0
the error is:
LibrianManager.java:37: cannot find symbol
symbol : constructor Library(java.lang.String,java.lang.String,java.uti l.ArrayLi
st<OpeningHours>,int)
location: class Library
Library librian1 = new Library("L1", "Mary Anderson", L1Hrs, 40);
^
LibrianManager.java:38: cannot find symbol
symbol : constructor Library(java.lang.String,java.lang.String,java.uti l.ArrayLi
st<OpeningHours>,int)
location: class Library
Library librian2 = new Library("L2", "Johnny Dept", L2Hrs, 40);
^
2 errors
- 11-14-2010, 09:49 AM #11
Member
- Join Date
- Nov 2010
- Posts
- 8
- Rep Power
- 0
yah, it is compilation error.. =(
- 11-14-2010, 10:02 AM #12
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
Whats a LibrianManager? Someone who keep a record of tetra grammaton clerics and takes a shot of prozium to the neck every hour?
Ever seen a dog chase its tail? Now that's an infinite loop.
- 11-14-2010, 12:45 PM #13
Member
- Join Date
- Nov 2010
- Posts
- 8
- Rep Power
- 0
- 11-14-2010, 12:48 PM #14
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
I was just trying to point out that it's spelled Librarians, not Librians. While spelling and grammar may not seem like an important part of programming now, code clarity and readability is a big part of working on bigger projects.
Last edited by m00nchile; 11-14-2010 at 01:26 PM. Reason: irony strikes, typo
Ever seen a dog chase its tail? Now that's an infinite loop.
- 11-14-2010, 01:08 PM #15
Member
- Join Date
- Nov 2010
- Posts
- 8
- Rep Power
- 0
oops ok. sorry. my bad. i didn't get the spelling right.
- 11-14-2010, 07:18 PM #16
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
LibrianManager.java:37: cannot find symbol
symbol : constructor Library(java.lang.String,java.lang.String,java.uti l.ArrayLi
st<OpeningHours>,int)
location: class Library
Library librian1 = new Library("L1", "Mary Anderson", L1Hrs, 40);
^
The "cannot find symbol" error means you have a typo or have misremembered the arguments that a method needs. Each of the four arguments you use when you construct a Library must be the same type as in the declaration: String/String/OpenHours/int.
You have changed the constructor to use an OpeningHours argument. However you are still using L1Hrs as the argument, and that's an ArrayList of OpeningHours as I pointed out yesterday.
- 11-14-2010, 07:55 PM #17
Member
- Join Date
- Nov 2010
- Posts
- 1
- Rep Power
- 0
Hi,
I'm having the same problem as the her in my own constructor.
1) Does it mean that she have to change her opening hours argument to match the arraylist?
for example
public Library(String dID, String pName, ArrayList<OpeningHours> wrkHrs, int hrRate){
id = dID;
name = pName;
workingHours = wrkHrs;
hourRate = hrRate;
}
- 11-14-2010, 10:46 PM #18
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
1) Does it mean that she have to change her opening hours argument to match the arraylist?
Either that or change the argument being used to an instance of OpeningHours.
Bear in mind that no-one here actually knows what the code is supposed to do. I would guess that the constructor should be altered to match how it is being used (as you suggest). So library 1 has a list two different opening hours for example.
But in that case the Library class looks a little weird. workingHours would have to a list of OpeningHours so that both days were part of the state of a library. (and the return type of getWrkHrs() correspondingly changed.)
This is just a guess. The assignment itself will say what has to be achieved.
- 11-19-2010, 03:53 PM #19
Member
- Join Date
- Nov 2010
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
convert byte array into char array
By kgkamaraj in forum New To JavaReplies: 4Last Post: 09-13-2011, 11:32 AM -
Variable of an object in an array compared to an element of another array?
By asmodean in forum New To JavaReplies: 23Last Post: 09-07-2010, 08:12 PM -
Trying to make an array list // inserting an element to middle of array
By javanew in forum New To JavaReplies: 2Last Post: 09-06-2010, 01:03 AM -
Array length and printing out uninitialized array.
By nicolek808 in forum New To JavaReplies: 4Last Post: 09-10-2009, 09:12 AM -
How to add an integer to a array element and the store that backinto an array.
By Hannguoi in forum New To JavaReplies: 1Last Post: 03-31-2009, 06:40 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks