吉软-人文精英班-第六次作业

答案:A

错误:1.右上处,调用有参构造方法错误,因为MyClass(int value)方法为default权限类型;

          2.右上处,调用value时错误,value为private;

          3.左下处,调用value时错误,value为private;

修改:1.把程序改到相同包中;

          2和3使用get方法替代value变量;

package work;
//银行账户
public class Account {
	private long Id;//账户
	private double balance;//账户余额
	private String password;//账户密码
	
	Account(long Id,double balance,String password)
	{
		this.Id=Id;
		this.balance=balance;
		this.password=password;
	}
	
	public long getId() {
		return Id;
	}
	public double getBalance() {
		return balance;
	}
	public void setBalance(double balance) {
		this.balance = balance;
	}
	public String getPassword() {
		return null;
	}
	public void setPassword(String password) {
		this.password = password;
	}
}

 

package work;
//储蓄账户
public class SavingAccount extends Account{
	private double interesrtRate;//存款利率

	SavingAccount(long Id,double balance,String password,double interesrtRate)
	{
		super(Id,balance,password);
		this.interesrtRate=interesrtRate;
	}
	
	public double getInteresrtRate() {
		return interesrtRate;
	}

	public void setInteresrtRate(double interesrtRate) {
		if(interesrtRate<0.1&&interesrtRate>0)
			this.interesrtRate = interesrtRate;
		else
			System.out.println("利率范围不正确,不予修改");
	}
	
	public void setPassword(String password)//修改
	{
		if(password.length()==6)
			super.setPassword(password);
		else
			System.out.println("不予修改");
	}
}

 

package work;
//信用账户
public class CreditAccount extends Account{
	private double creditLine;//信用额度

	CreditAccount(long Id,double balance,String password,double creditLine)
	{
		super(Id,balance,password);
		this.creditLine=creditLine;
	}
	
	public double getCreditLine() {
		return creditLine;
	}

	public void setCreditLine(double creditLine) {
		this.creditLine = creditLine;
	}
	
	public void setPassword(String password)//修改
	{
		if(password.length()==6)
			super.setPassword(password);
		else
			System.out.println("不予修改");
	}
}

 

package work;
//测试类
public class Text {
	public static void main(String[] args) {
		Account a=new Account(123,123,"123");//Account类
		System.out.println(a.getBalance());
		System.out.println(a.getId());
		System.out.println(a.getPassword());
		System.out.println();
		SavingAccount s=new SavingAccount(123,123,"123",0.1);//SavingAccount类
		System.out.println(s.getBalance());
		System.out.println(s.getId());
		System.out.println(s.getPassword());
		System.out.println(s.getInteresrtRate());
		s.setPassword("1234");
		s.setInteresrtRate(0.2);
		System.out.println();
		CreditAccount c=new CreditAccount(123,123,"123",0.9);//CreditAccount类
		System.out.println(c.getBalance());
		System.out.println(c.getId());
		System.out.println(c.getPassword());
		c.setCreditLine(0.5);
		System.out.println(c.getCreditLine());
		c.setPassword("123");
	}
}

 

转载于:https://my.oschina.net/u/3858170/blog/1819085

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值