I came across same issue as you. It was discussed in url below: http://groups.google.com/group/javaprogrammingwithpassion/browse_thread/thread/6572aac8f5378d66/f1cc5bd86c3de3f8?lnk=gst&q=#f1cc5bd86c3de3f8
In this discussion, Miga also suggested how to make use of the average argument. On Mar 20, 5:28 am, Ryu <[email protected]> wrote: > Hi to all, > Hope everyone is fine . I have a problem with lab as > mentioned in subject regarding (Exercise4 : Constructor) . Actually in > the modification it is being described that pass average as a > parameter and created annaRecord object with newly constructor . I > want to ask how , actually i try the things but it is of no use, I > couldn't get the result . > > What I understand is that I have to pass five parameters > to consructor including name, mathGrade, englishGrade, scienceGrade, > and average. First i tried this. > > public StudentRecord(String name, double mGrade, double eGrade, > double sGrade, double average){ > this(name, mGrade, eGrade, sGrade); > this.average = average; > } > > and in the ConstructorExample class I call it like > this. > > StudentRecord annaRecord = new StudentRecord("Anna", 10, 20, 30, > annaRecord.getAverage()); > > but after it, it shwos the error that " variable > annaRecord might not have been initialized ". > why this is happened although i made a object annaRecord > in the statement? > > Then I made every field of StudentRecord class static , > also made the getAverage() , getMath() , getEnglish(), and getScience > methods static and try this. > > public StudentRecord(String name, double mGrade, double eGrade, > double sGrade, double average){ > this(name, mGrade, eGrade, sGrade); > this.average = average; > System.out.println("name = " + name + " and average = " + > average); > } > > and call it like this. > > StudentRecord annaRecord = new StudentRecord("Anna", 10, 20, 30, > StudentRecord.getAverage()); > > ok there is no error but when i run the program it shows > the output like > > name = Anna and average = 0.0 > > why this show zero average ? tell me plz. > > What I try to do is that pass all five parameters > including name, math , sciene, english grades and then as a fifth > parameter call getAverage() method which return average of passed > math, science and english grades parameters and these all values go to > StudentRecord constructor and finally print name and average of > annaRecord > > When i examine my logic I conclude that although I > call the getAverage() method but I didn't set math, english and > science grades. > > Please give me some hint that how can I do this by > passing five parameters as i mention above to accomplish the task and > also want to ask that when I made fields and methods static all errors > removed although i didn't get the result, is there any way to solve > this without made fields and methods static? > > Is there any other logic to solve this problim please > tell me I really appreciate it > > Thanks in advance --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en -~----------~----~----~----~------~----~------~--~---
