• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:


 
Ranch Hand
Posts: 36
1
VI Editor Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???
 
Ranch Hand
Posts: 258
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 258
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic