| | |
Need help Using "get and set methods"
![]() |
•
•
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 |
911 addball addressbook android api append applet application apps array arrays automation binary bluetooth businessintelligence button card character class client code collision component crashcourse css csv database eclipse ee error fractal free game gis givemetehcodez graphics gui html ide image integer integration j2me japplet java javaarraylist javadoc javafx javaprojects jni jpanel julia jvm linux list loan machine map method methods migrate mobile netbeans newbie objects oriented output panel phone physics problem program programming project projects radio recursion replaydirector reporting researchinmotion scanner se server service set sms software sort sql string swing test textfield threads transfer tree trolltech ubuntu utility windows






