Results 1 to 19 of 19

Thread: array help!

  1. #1
    ah_gal06 is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default 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!

  2. #2
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    can you post your constructors for Library Class

  3. #3
    ah_gal06 is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default

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

  4. #4
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Your Library Constructor is looking for a WorkingHours Object and you are sending it a ConsultationHours object

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Isn't it being sent an ArrayList of OpeningHours?

    Either way you must send a WorkingHours instance.

  6. #6
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    yup you are right pbrockway2 it is an arraylist I made a mistake between the arraylist L1Hrs and the object L1First etc... its late :)

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,573
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by ah_gal06 View Post
    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;
    }
    What´s that ´public Doctor( ... )' thing doing there?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    ah_gal06 is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default

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

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,573
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by ah_gal06 View Post
    oops. sorry.. i m being careless.
    yup! i corrected both mistakes already.. but still can't..
    It's Sunday and I am not psychic today; you have to tell us what the errors were? Compilation errors? Runtime errors? What did they tell you (or were trying to tell you?)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    ah_gal06 is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default

    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. #11
    ah_gal06 is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default

    yah, it is compilation error.. =(

  12. #12
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    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.

  13. #13
    ah_gal06 is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by m00nchile View Post
    Whats a LibrianManager? Someone who keep a record of tetra grammaton clerics and takes a shot of prozium to the neck every hour?
    a place to keep track of the librians working hrs in the library..

  14. #14
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    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.

  15. #15
    ah_gal06 is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default

    oops ok. sorry. my bad. i didn't get the spelling right.

  16. #16
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    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.

  17. #17
    krust is offline Member
    Join Date
    Nov 2010
    Posts
    1
    Rep Power
    0

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

  18. #18
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    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.

  19. #19
    ah_gal06 is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

Similar Threads

  1. convert byte array into char array
    By kgkamaraj in forum New To Java
    Replies: 4
    Last Post: 09-13-2011, 11:32 AM
  2. Replies: 23
    Last Post: 09-07-2010, 08:12 PM
  3. Replies: 2
    Last Post: 09-06-2010, 01:03 AM
  4. Array length and printing out uninitialized array.
    By nicolek808 in forum New To Java
    Replies: 4
    Last Post: 09-10-2009, 09:12 AM
  5. Replies: 1
    Last Post: 03-31-2009, 06:40 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
  •