Cheers Mihai. That looks similar to what I'd done :)

James

On May 18, 5:41 pm, Mihai DINCA <mihai.di...@free.fr> wrote:
> Hi JKay
>
> You can have an int static (class level member) in the Student class
> that keeps the current count. Then a method that returns the next
> Integer, to be used in the class constructor. Something like this (it is
> not actually how I did, but it is about the same thing):
>
>     public class Sudent {
>         // The Student ID
>         *private Integer studentID = null;*
>         // The Student infos
>         private StudendRecord studentDetails = null;
>
>         // The constructor fills in the data about the student
>         *public Student()*{
>             // Increment the counter
>             *this.studentID = Student.nextCounter()*;
>             // Attach a StudentRecord
>             this.studentDetail = new StudentRecord();
>         }
>
>         // The static int value keeps the current ID
>         private static int *currentCounter* = 0;
>         // The following method increments the counter
>         private static Integer *nextCounter*(){
>             return new Integer( currentCounter++ );
>         }
>
>         .... and so on
>     }
>
> Hope it helps
> Mihai
>
> JKay a écrit :
>
>
>
>
>
> > Ok still having problems with this.
>
> > First problem - how to get studentId to increment? Can you do studentId
> > ++ for an Integer object? In the end I ended up making studentId a
> > class variable that is incremented and creating an instance variable
> > of int type called Id that holds the student's studentId. Otherwise
> > the studentId was always 3 when printed - might have just been
> > printing in the wrong order, but shouldn't you be able to assign each
> > student their own studentId?
>
> > Second problem - forgot what it was...
>
> > Have submitted the homework now, and it works, but don't feel its as
> > was intended. Could just be misinterpretation of the instructions on
> > my part though... For example:
>
> > The Student class has studentId instance variable whose type is
> > Integer type.
> > -I've made studentId a class variable and a separate instance variable
> > called Id.
>
> > On May 15, 11:05 am, "Nick Dolan" <nickdo...@gmail.com> wrote:
>
> >> Take studentercord out from settee Anna is the object and you call set on 
> >> that
>
> >> e.g
> >> anna.setName("Anna");
>
> >> Nick
> >>  07961171046
>
> >> -----Original Message-----
> >> From: Mihai DINCA <mihai.di...@free.fr>
> >> Date: Sat, 15 May 2010 11:05:35
> >> To: <jkendal...@gmail.com>
>
> >> Cc: Java Programming Online Training Course By Sang 
> >> Shin<javaprogrammingwithpassion@googlegroups.com>
> >> Subject: Re: [java programming] Re: Homework 1014
>
> >> I think your constructor for the class Student must do "studentRecord =
> >> new StrudentRecord()" or something like this.
>
> >> Hope it helps
> >> mihai
>
> >> JKay a écrit :
>
> >>> Tried to post the entire project here, but moderator said no.
> >>> Apparently we're not allowed to post large volumes of code, just small
> >>> snippets?
>
> >>> The project is 3 classes (StudentRecordExample.java[MAIN],
> >>> StudentRecord.java,Student.java), which have been modified from the
> >>> original MyStudentRecordExampleProject so its a bit bulky and could do
> >>> with a lot of streamlining, but I figure it should work anyways. As
> >>> said the error I'm getting is:
>
> >>> Exception in thread "main" java.lang.NullPointerException
> >>>         at StudentRecordExample.main(StudentRecordExample.java:35)
> >>> Java Result: 1
>
> >>> I used the 'new' keyword to create an instance of a Student object
> >>> like so in StudentRecordExample.java:
>
> >>> Student anna = new Student();
>
> >>> Then to set the name variable for object anna of class Student, I
> >>> used:
>
> >>> anna.studentRecord.setName("Anna");
>
> >>> which as I understand it gets method setName from class studentRecord.
> >>> Do I have to explicitly link classes Student and StudentRecord some
> >>> how for this to work? BTW this line of code where I set anna's name
> >>> variable is highlighted when I click on the error, and is on line 35.
>
> >>> On May 14, 6:00 pm, Nic Fox <f...@nicfox.com> wrote:
>
> >>>> Without seeing your code it's hard to say.
>
> >>>> So you've used the 'new' keyword to make an instance of a Student  
> >>>> object?
> >>>>         E.g. Student anna = new Student();
>
> >>>> And then you use something like:
> >>>>         anna.name = "Anna";
>
> >>>> If you've done those things then it could be an issue with variable  
> >>>> scope perhaps?
>
> >>>> On 14/05/2010, at 11:47 PM, JKay wrote:
>
> >>>>> I keep getting the following error when I run my program:
>
> >>>>> Exception in thread "main" java.lang.NullPointerException
> >>>>>        at StudentRecordExample.main(StudentRecordExample.java:35)
>
> >>>>> I looked up what java.lang.NullPointException is in the API and found
> >>>>> this:
>
> >>>>> "public class NullPointerException
> >>>>> extends RuntimeException
>
> >>>>> Thrown when an application attempts to use null in a case where an
> >>>>> object is required. These include:
>
> >>>>>    * Calling the instance method of a null object.
> >>>>>    * Accessing or modifying the field of a null object.
> >>>>>    * Taking the length of null as if it were an array.
> >>>>>    * Accessing or modifying the slots of null as if it were an array.
> >>>>>    * Throwing null as if it were a Throwable value.
>
> >>>>> Applications should throw instances of this class to indicate other
> >>>>> illegal uses of the null object."
>
> >>>>> Which as far as I understand means that I'm trying to do something
> >>>>> with a null object. Said object is object anna of class Student, and
> >>>>> the method on the line that is throwing the exception is me attempting
> >>>>> to set the name variable for anna to "Anna"
>
> >>>>> Any ideas?
>
> >>>>> James
>
> >>>>> --> To post to this group, send email 
> >>>>> tojavaprogrammingwithpass...@googlegroups.com> To unsubscribe from this 
> >>>>> group, send email 
> >>>>> tojavaprogrammingwithpassion+unsubscr...@googlegroups.com
> >>>>> For more options, visit this group 
> >>>>> athttp://groups.google.com/group/javaprogrammingwithpassion?hl=en
>
> >>>> --To post to this group, send email 
> >>>> tojavaprogrammingwithpass...@googlegroups.comto unsubscribe from this 
> >>>> group, send email 
> >>>> tojavaprogrammingwithpassion+unsubscr...@googlegroups.com
> >>>> For more options, visit this group 
> >>>> athttp://groups.google.com/group/javaprogrammingwithpassion?hl=en
>
> >> --
> >> To post to this group, send email to 
> >> javaprogrammingwithpassion@googlegroups.com
> >> To unsubscribe from this group, send email to 
> >> javaprogrammingwithpassion+unsubscr...@googlegroups.com
> >> For more options, visit this group 
> >> athttp://groups.google.com/group/javaprogrammingwithpassion?hl=en
>
> >> --
> >> To post to this group, send email to 
> >> javaprogrammingwithpassion@googlegroups.com
> >> To unsubscribe from this group, send email to 
> >> javaprogrammingwithpassion+unsubscr...@googlegroups.com
> >> For more options, visit this group 
> >> athttp://groups.google.com/group/javaprogrammingwithpassion?hl=en
>
> --
> To post to this group, send email to 
> javaprogrammingwithpassion@googlegroups.com
> To unsubscribe from this group, send email to 
> javaprogrammingwithpassion+unsubscr...@googlegroups.com
> For more options, visit this group 
> athttp://groups.google.com/group/javaprogrammingwithpassion?hl=en

-- 
To post to this group, send email to javaprogrammingwithpassion@googlegroups.com
To unsubscribe from this group, send email to 
javaprogrammingwithpassion+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en

Reply via email to