美文网首页
Day7-22下午自习

Day7-22下午自习

作者: c09d4d97eb9f | 来源:发表于2020-07-22 21:01 被阅读0次
    image.png

    Person类

    public class Person
    {
        String name;
        int age;
        Person(){}
        Person(String name, int age){
            this.name = name;
            this.age = age;
        }
    
        public String getName()
        {
            return name;
        }
    
        public void setName(String name)
        {
            this.name = name;
        }
    
        public int getAge()
        {
            return age;
        }
    
        public void setAge(int age)
        {
            this.age = age;
        }
    
    

    Teacher类:

    public class Teacher extends Person
    {
        String kecheng;
        Teacher(){}
        Teacher(String kecheng){
           this.kecheng = kecheng;
        }
    
        public String getKecheng()
        {
            return kecheng;
        }
    
        public void setKecheng(String kecheng)
        {
            this.kecheng = kecheng;
        }
        public void showMsg(){
            System.out.println(this.age+"岁的"+this.name+",讲授了"+kecheng+"课" );
        }
    
    

    student类:

    public class Student extends Person
    {
        int num;
            Student(){}
        Student(int num, String kaoshi){
            this.num= num;
        }
        public int getNum()
        {
            return num;
        }
        public void setNum(int num)
        {
            this.num = num;
        }
        public  void showMsg(){
            System.out.println(this.age+"岁的"+this.name+",考试得了"+num+"分");
        }
    

    结果:


    image.png image.png

    Auto类:

    public class Auto
    {
        String pinpai;
        double chechang;
        double jiage;
    
        public String getPinpai()
        {
            return pinpai;
        }
    
        public void setPinpai(String pinpai)
        {
            this.pinpai = pinpai;
        }
    
        public double getChechang()
        {
            return chechang;
        }
    
        public void setChechang(double chechang)
        {
            this.chechang = chechang;
        }
    
        public double getJiage()
        {
            return jiage;
        }
    
        public void setJiage(double jiage)
        {
            this.jiage = jiage;
        }
        public  void panduan (){
            if (chechang<=4295){
    
            }
        }
    

    SUV类

    public class SUV extends Auto
    {
    
        public void panduan()
        {
            if (this.chechang > 4295 && this.chechang <= 5070) {
                System.out.println("车型:" + this.pinpai + "\n" + "价格:" + this.jiage + "\n" + "车长:"+chechang);
            } else if (this.chechang <= 4295) {
                System.out.println("车型:" + this.pinpai + "\n" + "价格:" + this.jiage + "\n" + "车长:"+chechang);
            } else if (this.chechang > 5070) {
                System.out.println("车型:" + this.pinpai + "\n" + "价格:" + this.jiage + "\n" + "车长:"+chechang);
            }
        }
    

    测试类:

        public static void main(String[] args)
        {
            ArrayList<String> list = new ArrayList<>();
            SUV a  = new SUV();
            SUV b  = new SUV();
            SUV c  = new SUV();
            SUV d  = new SUV();
            a.chechang= 4813.0;
            a.jiage = 76000.0;
            a.pinpai="SUV";
            b.chechang = 4545.0;
            b.jiage = 188800.0;
            b.pinpai = "SUV";
            c.chechang= 4100.0;
            c.jiage = 199999.0;
            c.pinpai = "小车";
            d.chechang = 5100.0;
            d.jiage = 888888.0;
            d.pinpai = "大车";
            a.panduan();
            b.panduan();
            c.panduan();
            d.panduan();
        }
    

    结果:


    image.png

    相关文章

      网友评论

          本文标题:Day7-22下午自习

          本文链接:https://www.haomeiwen.com/subject/wlazkktx.html