java学习——student类

 这是自己自学一周写的粗糙学生类,其中还有些问题,大佬勿喷,如果能给我说写解决的方法的感激不尽

package t1;

public class test {
    public static void main(String[] args) {
        Collage col=new Collage();
        System.out.println("学生号"+'\t'+'\t'+"姓名"+'\t'+"年龄"+'\t'+"java成绩"+'\t'+"学校"+"(前面带*号的数据表示有误后的默认值");
        col.setStu_id("20180505025");
        col.setStu_name("张豪辉");
        col.setStu_age(999);
        col.setStu_score(120);
        System.out.println(col.getStu_id()+'\t'+col.getStu_name()+'\t'+col.getStu_age()+'\t'+col.getStu_score()+'\t'+col.getCollage());

    }
}
package t1

public class Student {
    //定义属性
    private String stu_id;
    private String stu_name;
    private int stu_age;
    private int stu_score;
    //定义方法
    //封装
    public String getStu_id() {
        return stu_id;
    }

    public void setStu_id(String stu_id) {
        if(stu_id.length()!=12){
            System.out.print("*NULL");
        }
        this.stu_id = stu_id;
    }
    public String getStu_name() {
        return stu_name;
    }

    public void setStu_name(String stu_name) {
        this.stu_name = stu_name;
    }

    public int getStu_age() {
        return stu_age;
    }

    public void setStu_age(int stu_age) {
        if(stu_age>=100 || stu_age<0){
            System.out.print("*");
            stu_age=20;
        }
        this.stu_age = stu_age;
    }

    public int getStu_score() {
        return stu_score;
    }

    public void setStu_score(int stu_score) {
        if(stu_score>100 || stu_score<0){
            System.out.print("*");
            stu_score=60;
        }
        this.stu_score = stu_score;
    }
}
package t1;

public class Collage extends Student{
    private String collage="郑州升达经贸管理学院";

    public String getCollage() {
        return collage;
    }

    public void setCollage(String collage) {
        this.collage = collage;
    }
    
}

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

BayMin0520

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值