public class Person {
public static void main(String[] args) throws Exception {
Person person = new Person("张三","男",20);
System.out.println(person) ;
}
private String name = "";
protected String gradel="";
int age = 0;
public Person() {
}
public Person(String name, String gradel, int age) throws Exception {
if (!("男".equals(gradel) || "女".equals(gradel))) {
throw new Exception("性别只能是男或者女");
}
if (age < 0 || age > 130) {
throw new Exception("年龄超过范围");
}
this.name = name;
this.gradel = gradel;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGradel() {
return gradel;
}
public void setGradel(String gradel) {
this.gradel = gradel;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
", gradel='" + gradel + '\'' +
", age=" + age +
'}';
}
}
你是哪个地方有问题呢?哪一步做不下去?
https://mall.csdn.net/item/83076?spm=1001.2101.3001.5845
兄弟送你个教程