java-java57-第七次作业

一、People类

package org.jsoft.FengZhuang;

public class People {        //人
    private float height;
    private float weight;
    
    public float getHeight() {
        return height;
    }
    public void setHeight(float height) {
        this.height = height;
    }
    public float getWeight() {
        return weight;
    }
    public void setWeight(float weight) {
        this.weight = weight;
    }
    
    public void speakHello(){
        System.out.println("Hello");
    }
    
    public float averageHeight(){
        return getHeight();
    }
    public float averageWeight(){
        return getWeight();
    }
}

 

package org.jsoft.FengZhuang;

public class ChinaPeople extends People{        //中国人
    public String chinaMartial(){
        return "太极,武术,拳法";
    }
    public void speakHello(){
        System.out.println("打招呼说您好!");
    }
    public float averageHeight(){
        return this.getHeight();
    }
    public float averageWeight(){
        return this.getWeight();
    }
}

 

package org.jsoft.FengZhuang;

public class AmericanPeople extends People{    //美国人
    public String AmericanBoxing(){
        return "搏击,格斗";
    }
    public float averageHeight(){
        return this.getHeight();
    }
    public float averageWeight(){
        return this.getWeight();
    }
}

package org.jsoft.FengZhuang;

public class BeijingPeople extends ChinaPeople{        //北京人
    public String BeijingOpera(){
        return "说唱脸谱";
    }

    public float averageHeight(){
        return this.getHeight();
    }
    public float averageWeight(){
        return this.getWeight();
    }
}

113827_VOYb_3715432.png

 

 

二、Account类

 

package org.jsoft.FengZhuang;

public class Account {
    private long id;        //账户id
    private double balance;        //账户余额
    private String passward;    //账户密码
    
    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 getPassward() {
        return null;
    }
    public void setPassward(String passward) {
        if(passward.length()==6){
        this.passward = passward;
        }else{
            System.out.println("密码不是六位,修改失败");
        }
    }
}

 

package org.jsoft.FengZhuang;

public class SavingAccount extends Account{
    private double interestRate; //存款利率

    public double getInterestRate() {
        return interestRate;
    }
    
    public void setPassward(String passward) {
        if(passward.length()==6){
        super.setPassward(passward);
        System.out.println("储蓄帐户"+super.getId()+"密码修改成功");
        }else{
            
            System.out.println("密码不是六位,修改失败");
        }
    }
    public void setInterestRate(double interestRate) {
        if(interestRate>0&&interestRate<0.1){
        this.interestRate = interestRate;
        }
    }
    
}
 

package org.jsoft.FengZhuang;

public class CreditAccount extends Account{
        private double creditLine;

        public double getCreditLine() {
            return creditLine;
        }

        public void setCreditLine(double creditLine) {
            this.creditLine = creditLine;
        }
        public void setPassward(String passward) {
            if(passward.length()==6){
            super.setPassward(passward);
            System.out.println("信用用户"+super.getId()+"密码修改成功");
            }else{
                
                System.out.println("密码不是六位,修改失败");
            }
        }
}
 

package org.jsoft.FengZhuang;

public class TestAccount {
    public static void main(String[] args) {
    SavingAccount saveAccount=new SavingAccount();
    saveAccount.setId(123456789);
    saveAccount.setPassward("266666");
    saveAccount.setBalance(800);
    saveAccount.setInterestRate(0.08);
    System.out.println("储蓄银行的利率为:"+saveAccount.getInterestRate()); 
    
    CreditAccount creditAccount=new CreditAccount();
    creditAccount.setId(987654321);
    creditAccount.setPassward("111111");
    creditAccount.setBalance(117);
    System.out.println("信用帐户"+creditAccount.getId()+"的信用额度为"+creditAccount.getBalance());
}
}
三、 A

四、

右上角

在不同包类:MyClass mc2=new MyClass(10);  不能调用缺省的构造函数

私有类型不能直接点出来

左下角

私有类型不能直接点出来

转载于:https://my.oschina.net/u/3715432/blog/1571533

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值