package cn.campsg.java.experiment;
public class Student {
private String name;
private int age;
private boolean sex;
private float score;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
if(age<18){
this.age=18;
}
else{
this.age=age;
}
}
public String getSex() {
if(sex==true) {
return "男";
}
else{
return "女";
}
}
public void setSex(boolean sex) {
this.sex = sex;
}
public float getScore() {
return score;
}
public void setScore(float score) {
this.score = score;
}
public Student(){
this("",0,true,0.0f);
}
Student(String name,int age,boolean sex,float score){
this.name=name;
this.age=age;
this.sex=sex;
this.score=score;
}
}
package cn.campsg.java.experiment;
public class MainClass {
public static void main(String[] args) {
Student student = new Student("黄世仁",24,true,59.0f);
System.out.println("姓名:"+student.getName());
System.out.println("年龄:" + student.getAge());
System.out.println("性别:" + student.getSex());
System.out.println("分数:" + student.getScore());
}
}