Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: construcctor

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile construcctor

    public Unit(String code, String name)
    {
    enrolStudent(student);
    this.unitCode = code;
    this.unitName = name;

    }

    public void enrolStudent(Student newStudent){
    students = new ArrayList<Student>();
    newStudent = new Student(24662496, "Kingsley", " Iwunze");
    students.add(newStudent);
    }

    please how can I call this enrolStudent() method on this Unit constructor in another class when I create a new Unit. all I need is to enroll students in units when units are created. below is my create unit method.

    public void createUnits( ){
    units = new ArrayList<Unit>();



    units.add(new Unit("FIT2034", "Java Programming 2"));

    units.add(new Unit("FIT2024", "Software Engineering"));
    units.add(new Unit("MAT1830","Discrete Maths"));


    unit.enrolStudent(new Student(25486321, "Julia", "Garcia"));
    unit.enrolStudent(new Student(44589736, "James", "Olivia"));
    unit.enrolStudent(new Student(47852103, "Lucky", "Thyriod"));


    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: construcctor

    Moved from Introductions section.

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    how can I call this enrolStudent() method
    Create an instance of the Unit class and use that to call its methods.
    Unit unt = new Unit();   // create an instance of the class
    unt.theMethodToCall(THE ARGS HERE); // call its methods
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: construcctor

    Welcome to the forum!