1-Declare a class that describes a person. The class should have the following
instance variables:
name: String
age: double
id: long
street: String
city: String
The class should have at least two different constructors and the method details
that print the person details.
You should test this class by instantiating it and check the details method.
public class Person{
private String name;
private double age;
private long id;
private String street;
private String city;
public Person() {
super();
}
public Person(String name, double age, long id, String street, String city) {
super();
this.name = name;
this.age = age;
this.id = id;
this.street = street;
this.city = city;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getAge() {
return age;
}
public void setAge(double age) {
this.age = age;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
@Override
public String toString() {
return "Person [name=" + name + ", age=" + age + ", id=" + id + ", street=" + street + ", city=" + city + "]";
}
} public class Principal { public static void main(String[] args) { Person p = new Person(); p.setName("Nikola Tesla"); p.setAge(86); p.setId(1007); p.setStreet("Share3 5"); p.setCity("Nueva York"); System.out.println(p.toString()); }
}
التعليقات