| | |
Need help Using "get and set methods"
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2004
Posts: 7
Reputation:
Solved Threads: 0
I'm using the Scanner class and need help in setting up get and set methods for where the program asks the user to enter a first name and a last name as String type.( 2 methods, 1 for first, 1 for last) I need to know how to store the names because...
I am creating a client of the first class and need to call the methods in order to display what the user inputted at the end of the program.
How do you type code for this?
Any help is appreciated.
I am creating a client of the first class and need to call the methods in order to display what the user inputted at the end of the program.
How do you type code for this?
Any help is appreciated.
First, do you really need set methods? Most of the time you can use constructor arguments to set the fields and set methods aren't required:
Then writing the get methods only consists of returning the necessary field. The chances of an object representing a person needing to change the name are very slim, so set methods don't make much sense except in very specific situations.
Java Syntax (Toggle Plain Text)
Scanner in = new Scanner ( System.in ).useDelimiter ( ' ' ); System.out.print ( "Full name (ex. John Smith): " ); String first = in.next(); String last = in.next(); Client obj = new Client ( first, last );
I'm here to prove you wrong.
![]() |
Similar Threads
- get/set Methods in java (Java)
- Conceptual Understand of Get and Set Methods (Java)
- Pls helpme in replacing set and get methods with List (Java)
- "Set as Startpage" for Firefox. (HTML and CSS)
Other Threads in the Java Forum
- Previous Thread: Help with Tertiary trees?!?!
- Next Thread: creating a frame with four clocks
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class classes client code compile compiler component database developmenthelp eclipse error fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui html ide image input integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loop loops mac main map method methods mobile myregfun netbeans newbie notdisplaying number online page print problem program programming project qt recursion scanner screen server set singleton size sms sort spamblocker sql string swing system template textfields threads time title tree tutorial-sample update variablebinding windows working xor






