admin管理员组文章数量:1647990
//定义银行账户类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("存钱失败");
}
}
}
版权声明:本文标题:定义银行账户类Account,有属性:卡号cid,余额balance,所属用户Customer银行账户类Account有方法: (1)getInfo(),返回String类型,返回卡的详细信息 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1729495550a1202864.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论