Java Reference
In-Depth Information
We still must change the Employee constructor to accept all five pieces of information.
4.
In Employee, change the constructor header to the following:
public Employee(String name, String street,
String city, String state, String zip) {
5.
Replace the constructor body with the following code:
this .setEmpName(name);
this .setEmpStreet(street);
this .setEmpCity(city);
this .setEmpState(state);
this .setEmpZip(zip);
This code will use the setters to put the passed data into the private variables.
Finally, we need to delete the setName and getName methods we created earlier.
6.
In the outline pane (far right), right-click setName and, from the shortcut menu,
click Delete .
7.
At the “Confirm Delete” window, click the OK button.
8.
Delete the getName method, just as you deleted setName in steps 6 and 7.
9.
Format and save the source code.
The executable code should look similar to the following:
package c3;
public class Employee {
private String empName = new String();
private String empStreet, empCity, empState, empZip;
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public String getEmpStreet() {
return empStreet;
}
public void setEmpStreet(String empStreet) {
this.empStreet = empStreet;
}
public String getEmpCity() {
return empCity;
}
Search WWH ::




Custom Search