Final answer:
To create a person class in Java with attributes and appropriate set and get methods, define the class with private instance variables for name, age, and address, and provide public setter and getter methods for each attribute. In a separate class, create an object of type Person and use the setter methods to set the attribute values. Use FileWriter and BufferedWriter to write the attributes onto a .dat file.
Step-by-step explanation:
To create a person class in Java with attributes and appropriate set and get methods, you can define the class with private instance variables for name, age, and address, and provide public setter and getter methods for each attribute.
For example:
public class Person {
private String name;
private int age;
private String address;
// Setters
public void setName(String name) {
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
public void setAddress(String address) {
this.address = address;
}
// Getters
public String getName() {
return name;
}
public int getAge() {
return age;
}
public String getAddress() {
return address;
}
}
In a separate class that creates an object of type Person, you can set values for the attributes using the setter methods. To write the attributes onto a file with the .dat extension, you can use the FileWriter and BufferedWriter classes.