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 4 of 4

Thread: Basic java- objects & classes

  1. #1
    Member
    Join Date
    Oct 2013
    Posts
    31
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Basic java- objects & classes

    Hello everyone,

    I am attempting a problem in my second computer science course. I am very confused at the moment. Any help would be appreciated.


    "Create class Sess. A Sess object is to contain a reference to a Pupil object, a reference to a Tutor object and an additional attribute that refers to the date and time of an appointment between the tutor and the pupil. Write a tester that creates several Tutor objects, several Pupil objects, and several Session objects. Your tester should demonstrate that from a reference to a session you can display the data about the pupil and the tutor associated with the given visit. (You can use each of your Tutor objects and each of your Pupil objects for several Session objects.) "


    I already have made the Pupil and Tutor classes. First of all, how do I create an object that contains a reference?


    * I am currently reading information from this link:
    http://docs.oracle.com/javase/tutori...tcreation.html

    Sess object1 = new Sess();

    Pupil object1 = new Pupil();


  2. #2
    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: Basic java- objects & classes

    A Sess object that contains a reference to a Pupil object could be:
    class Sess
    {
        // a reference to a Pupil
        Pupil pupil;
     
        // a default constructor
        public Sess()
        {
            // initialize the pupil object
            pupil = new Pupil();
     
            // etc . . . 
        }
    }
    [COLOR="Silver"]

  3. #3
    Member
    Join Date
    Oct 2013
    Posts
    31
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Basic java- objects & classes

    Thank you. That makes sense.. I'm trying to do some more reading on the chapter / oracle docs. I'm a long way from understanding OOP.

  4. #4
    Member
    Join Date
    Oct 2013
    Posts
    31
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Basic java- objects & classes

    Actually, that is not compiling for some reason. Geany says it cannot find the symbol. Do I need to extend Session to Pupil or something of the sort?

    Edit:

    Wow I can't even get the fundamentals right. Really need to start working harder. The problem was that I was using Geany-- I had four java files all in the same project, but it wasn't viewing them as all being together. (Is the word for that "package"?)

    I'm using BlueJ now and it compiles fine.

Similar Threads

  1. CS 170 Java Objects And Classes Help
    By Tdc740 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 22nd, 2013, 12:18 PM