This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getFirstName from one class (set & get) to another class (Main Program)

 
Ween Li
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
1
Chrome Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 255
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ween Li
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 255
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic