| Author |
getFirstName from one class (set & get) to another class (Main Program)
|
Ween Li
Greenhorn
Joined: Aug 30, 2010
Posts: 4
|
|
Hi there
i have student class & MainApp class
How do i get getFirstName() method that returns the first name of the student from user input from Student record instance in MainApp class which contains?
array of 8 Student objects:
|
 |
S. Nitesh
Ranch Hand
Joined: Jan 15, 2010
Posts: 31
|
|
I assume that you want to know the usage of getter methods..
You can call the getter methods like below..
this will print "Aaron Ang" on console.
Is that you want???
|
 |
Raymond Tong
Ranch Hand
Joined: Aug 15, 2010
Posts: 156
|
|
I guess you want to extract the First Name from the Full Name?
You may find the link below useful
String in Java
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
|
I would advise you to create a getter/setter for both firstname and lastname. Because if the first or last name contains a space then you won't be able to separate them.
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
Ween Li
Greenhorn
Joined: Aug 30, 2010
Posts: 4
|
|
Hi Nitesh
i'm suppose to create an array to store 8 students, user will need to input data 8 student data - name & gpa only
Each element reference to Student class.
it should print "Aaron" as the first name when e.g: "Aaron Carter" & calculate the average gpa is input.
Thanks
|
 |
Raymond Tong
Ranch Hand
Joined: Aug 15, 2010
Posts: 156
|
|
Ween Li wrote:Hi Nitesh
i'm suppose to create an array to store 8 students, user will need to input data 8 student data - name & gpa only
Each element reference to Student class.
it should print "Aaron" as the first name when e.g: "Aaron Carter" & calculate the average gpa is input.
Thanks
To extract the First Name from the Full Name, you can have a look on the Java String API.
To calculate the average GPA, it is just simple maths. You should have no problem. But If you do, post your code and we would help.
|
 |
 |
|
|
subject: getFirstName from one class (set & get) to another class (Main Program)
|
|
|