定义银行账户类Account,有属性:卡号cid,余额balance,所属用户Customer 银行账户类Account有方法: (1)getInfo(),返回String类型,返回卡的详细信息

//定义银行账户类Account,有属性:卡号cid,余额balance,所属用户Customer   
//银行账户类Account有方法:
//(1)getInfo(),返回String类型,返回卡的详细信息
//(2)取钱方法withdraw(),参数自行设计,如果取钱成功返回true,失败返回false
//(3)存钱方法save(),参数自行设计,如果存钱成功返回true,失败返回false
//注:
//1.其中Customer类有姓名、身份证号、联系电话、家庭地址等属性
//2.Customer类有方法say(),返回String类型,返回他的个人信息。
//3.在测试类Bank中创建银行账户类对象和用户类对象,并设置信息,与显示信息
class Account
{
	private int id;
	private double balance;
	private Customer customer;

	public boolean save(int in_balance)
	{
		if (in_balance > 0)
		{
			balance += in_balance;
			return true;
		}
		return false;
	}

	public boolean withdraw(int out_balance)
	{
		if (out_balance <= balance)
		{
			balance -= out_balance;
			return true;
		}

		return false;
	}

	public int getId()
	{
		return id;
	}

	public void setId(int id)
	{
		this.id = id;
	}

	public double getBalance()
	{
		return balance;
	}

	public void setBalance(double balance)
	{
		this.balance = balance;
	}

	public Customer getCustomer()
	{
		return customer;
	}

	public void setCustomer(Customer customer)
	{
		this.customer = customer;
	}

	protected Account(int id, double balance, Customer customer)
	{
		super();
		this.id = id;
		this.balance = balance;
		this.customer = customer;
	}

	public String getInfo()
	{
		String info = "id:" + id + "\n余额:" + balance + "\n用户:" + customer.getName();
		return info;
	}

}

class Customer
{
	private String name;
	private String id_card;
	private String number;
	private String home_address;

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public String getId_card()
	{
		return id_card;
	}

	public void setId_card(String id_card)
	{
		this.id_card = id_card;
	}

	public String getNumber()
	{
		return number;
	}

	public void setNumber(String number)
	{
		this.number = number;
	}

	public String getHome_address()
	{
		return home_address;
	}

	public void setHome_address(String home_address)
	{
		this.home_address = home_address;
	}

	protected Customer(String name, String id_card, String number, String home_address)
	{
		super();
		this.name = name;
		this.id_card = id_card;
		this.number = number;
		this.home_address = home_address;
	}

	public String say()
	{
		String info = "姓名:" + name + "\n身份证号:" + id_card + "\n电话:" + number + "\n家庭住址:" + home_address;
		return info;
	}
}

public class MainTest
{
	public static void main(String[] args)
	{
		Customer customer = new Customer("王小明", "45721200509125334", "12345678965", "地球村");
		Account account = new Account(10001, 5000, customer);
		System.out.println(account.getInfo());
		System.out.println("***********************************");
		System.out.println(customer.say());
		System.out.println("***********************************");
		if (account.withdraw(10000) == true)
		{
			System.out.println("取钱成功。");
			System.out.println("还剩余额:" + account.getBalance());
		} else
		{
			System.out.println("取钱失败。");
		}
		System.out.println("***********************************");
		if (account.save(1000) == true)
		{
			System.out.println("存钱成功");
			System.out.println("余额:" + account.getBalance());
		} else
		{
			System.out.println("存钱失败");
		}
	}
}

  • 6
    点赞
  • 47
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值