Difference between revisions of "Person class lab assignment"
From WLCS
Line 1: | Line 1: | ||
+ | ---- | ||
+ | <div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;"> | ||
+ | ---- | ||
+ | =[http://ipelasuq.co.cc This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page]= | ||
+ | ---- | ||
+ | =[http://ipelasuq.co.cc CLICK HERE]= | ||
+ | ---- | ||
+ | </div> | ||
== Person class == | == Person class == | ||
Create a Person class using the following specifications: | Create a Person class using the following specifications: | ||
Line 35: | Line 43: | ||
− | + | <source lang="java"> | |
Person p = new Person(); | Person p = new Person(); | ||
System.out.println(p); //automatically calls the toString() method | System.out.println(p); //automatically calls the toString() method | ||
− | + | </source> | |
Revision as of 05:04, 24 November 2010
Person class
Create a Person class using the following specifications:
Attributes:
- first name
- last name
- birthdate
- id number
- height
- weight
- hair color
- eye color
Methods:
- Create a default constructor
- Create a specific constructor
- Create all the setters (mutators) for the listed attributes
- Create all the getters (accessors) for the listed attributes
Starting Template:
- Using PersonTestMain.java
- Create an instance of Person using the default constructor.
- Print out all the attributes using the getter methods.
- Change the attributes to different values by using the setter methods.
- Print out the attributes again.
toString() method
- Using the example below in your main() method, print out your Person variable:
<source lang="java">
Person p = new Person();
System.out.println(p); //automatically calls the toString() method
</source>
- What did you see when you tried to print the Person variable?
- Add a new method named toString() to your class
- toString() should return a String
- toString() should not have any parameters
- Create a String in the method that contains all your attributes
- return the String
- Now run your main() method again. What do you see?