吉软_Java57_第七次作业

7c96f826459503a3d7659f6c290756642af458e1_1_690x217.png

59292433556b8227d49624f7c611de6b6ea38d31_1_690x432.png

71e245dfb7903a6c5320d3d41a332056e1424873.png

c125ad47df7b35f5c5a0557d3c16521728bfc600_1_690x333.png

 

1.

package org.jsoft;

public class People {
    private String height,weight;
    public String getHeight() {
        return height;
    }

    public void setHeight(String height) {
        this.height = height;
    }

    public String getWeight() {
        return weight;
    }

    public void setWeight(String weight) {
        this.weight = weight;
    }
    public String speakHello(){
        return "say hello!";
    }
    public double averageHeight(){
        return 170;
    }
    public double averageWeight(){
        return 120;
    }
 }

package org.jsoft;

public class ChinaPeople extends People{
    //新增方法
            public String chinaMartial(){
                return "中国人会武术";
            }
    //重写方法
            public String speakHello(){
                return "ChinaPeople can say hello";
            }
            public double averageHeight(){
                return 170;
            }
            public double averageWeight(){
                return 130;
            }
     }

package org.jsoft;

public class AmericanPeople extends People{
    //新增方法
    public String americanBoxing(){
        return "AmericanPeople can say Boxing";
    }
    //重写方法
    public String speakHello(){
        return "say hello";
    }
    public double averageHeight(){
        return 185;
    }
    public double averageWeight(){
        return 140;
    }
}

package org.jsoft;

public class BeijingPeople extends People{
    //新增方法
    public String beijingOpera(){
        return "beijingPeople can beijingOpera";
    }
    //重写方法
    public String speakHello(){
        return "say hello";
    }
    public double averageHeight(){
        return 176;
    }
    public double averageWeight(){
        return 135;
    }
}

//测试

package org.jsoft;

import java.util.Scanner;

public class TextPeoleAll {
    public static void main(String[] args) {
        //测试People
        People p=new People();
        
        //测试ChinaPeople
        ChinaPeople c=new ChinaPeople();
        
        //测试AmericanPeople
        AmericanPeople a=new AmericanPeople();
        
        //测试BeijingPeople
        BeijingPeople b=new BeijingPeople();
        
        System.out.println(c.chinaMartial());
        System.out.println("中国人平均身高:"+c.averageHeight());
        System.out.println("中国人平均体重:"+c.averageWeight());
        System.out.println(c.speakHello());
        
        System.out.println(a.americanBoxing());
        System.out.println("美国人平均身高:"+a.averageHeight());
        System.out.println("美国人平均体重:"+a.averageWeight());
        System.out.println(a.speakHello());
        
        System.out.println(b.beijingOpera());
        System.out.println("北京人平均身高:"+b.averageHeight());
        System.out.println("北京人平均体重:"+b.averageWeight());
        System.out.println(b.speakHello());
    }
}

//结果

中国人会武术
中国人平均身高:170.0
中国人平均体重:130.0
ChinaPeople can say hello
AmericanPeople can say Boxing
美国人平均身高:185.0
美国人平均体重:140.0
say hello
beijingPeople can beijingOpera
北京人平均身高:176.0
北京人平均体重:135.0
say hello

2.

package org.jsoft;

public class Account {
    
        private long id;
        private double balance;
        private String password;
        
        public long getId() {
            return id;
        }
        public void setId(long id) {
            this.id = id;
        }
        public double getBalance() {
            return balance;
        }
        public void setBalance(double balance) {
            this.balance = balance;
        }
        public String getPassword() {
            return null;
        }
        public void setPassword(String password) {
            if (password.length()==6) {
            this.password = password;
            System.out.println("修改密码成功");
            } 
            else {
              System.out.println("输入错误,请重新输入");
       }

       this.password = password;
        }
}

package org.jsoft;

public class SavingAccount extends Account{
    
    private double interestRate;
    public long id(){
        return  021602;
    }

    public double getInterestRate() {
        return interestRate;
    }
    

    public void setInterestRate(double interestRate) {
        if(interestRate>0&&interestRate<0.1){
        this.interestRate = interestRate;
        System.out.println("利率正确");
        }else{
            System.out.println("请重新输入:");
        }
    }
}

package org.jsoft;

public class CreditAccount extends Account{
    Account a=new Account();
    private double creditLine;

    public double getCreditLine() {
        return creditLine;
    }

    public void setCreditLine(double creditLine) {
        this.creditLine = creditLine;
    }
     
}

//测试

package org.jsoft;

import java.util.Scanner;

public class TextAccount {
    public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    System.out.println("是否修改密码:");
     String x = sc.next();
    if(x!= null){
        Account a = new Account();
        System.out.println("请输入新密码:");
        Scanner sc1=new Scanner(System.in);
        String p = sc1.next();
        a.setPassword(p);
    }
    SavingAccount s=new SavingAccount();
    System.out.println("请输入利率:");
    Scanner sc2=new Scanner(System.in);
    double l=sc2.nextDouble();
    s.setInterestRate(l);
    }
}

//结果

是否修改密码:

请输入新密码:
123333
修改密码成功
请输入利率:
0.02
利率正确
 

3.A

4.

mc1.value改成mc1.getValue()

mc2.value改成mc2.getValue()

 

mc1.value改成mc1.getValue()

mc2.value改成mc2.getValue()

转载于:https://my.oschina.net/u/3716148/blog/1571235

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值