java作业:创建一个银行,银行里面有5个账户(账号,密码,钱)。要求:1、开户;2、开户以后才能
答案:2 悬赏:20 手机版
解决时间 2021-03-15 14:42
- 提问者网友:趣果有间
- 2021-03-15 04:36
java作业:创建一个银行,银行里面有5个账户(账号,密码,钱)。要求:1、开户;2、开户以后才能
最佳答案
- 五星知识达人网友:慢性怪人
- 2021-03-15 05:58
java控制台程序吗, 这个挺简单的呀, 2227421573详细的需求发过来, 是用java控制台做,还是要用jsp来做,还是要用java swing来做, 这个没有说明,
全部回答
- 1楼网友:酒醒三更
- 2021-03-15 06:17
两个实体类
实体类1:
public class Bank {
private List
public Bank() {
super();
}
public Bank(List
super();
this.list = list;
}
public List
return list;
}
public void setList(List
this.list = list;
}
}
实体类2:
public class Card {
private String id;
private String password;
private String isOpen; //判断是否开户 0开户 1没开户
private double money;
public Card() {
super();
}
public Card(String id, String password, String isOpen ,double money) {
super();
this.id = id;
this.password = password;
this.isOpen = isOpen;
this.money = money;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getIsOpen() {
return isOpen;
}
public void setIsOpen(String isOpen) {
this.isOpen = isOpen;
}
@Override
public String toString() {
return "Card [id=" + id + ", password=" + password + ", isOpen=" + isOpen + ", money=" + money + "]";
}
}
逻辑处理类:
public class TestService {
public Bank addUserInfo(){
Card card = new Card("1","1","0",10000);
Card card1 = new Card("2","2","1",20000);
Card card2 = new Card("3","3","1",30000);
Card card3 = new Card("4","4","1",40000);
Card card4 = new Card("5","5","1",50000);
List
list.add(card);
list.add(card1);
list.add(card2);
list.add(card3);
list.add(card4);
Bank bank = new Bank();
bank.setList(list);
List
return bank;
}
public Card login(Bank bank , String id,String password){
Card card1 = null;
List
for (Card card : list) {
if(id.equals(card.getId()) && password.equals(card.getPassword())){
card1 = card;
break;
}
}
return card1;
}
}
测试类:
public class Test {
public static void main(String[] args) {
TestService service = new TestService();
Bank bank = service.addUserInfo();
System.out.println("****************************");
System.out.println("*********欢迎进入银行系统********");
System.out.println("****************************");
Scanner input = new Scanner(System.in);
System.out.println("请输入卡号");
String id = input.next();
System.out.println("请输入密码");
String password = input.next();
Card card = service.login(bank , id, password);
if(card != null){
System.out.println("登陆成功");
}else{
System.out.println("登陆失败 ");
}
System.out.println("请选择你要的操作");
System.out.println("1.取款 2.查询余额 3.注销");
Scanner input1 = new Scanner(System.in);
String aa = input1.next();
if(aa.equals("3")){
System.out.println("注销成功");
}else if(aa.equals("2")){
System.out.println("卡号是:"+card.getId()+"余额是:"+card.getMoney());
}else if(aa.equals("1")){
if(card.getIsOpen().equals("1")){
System.out.println("对不起您的卡号没有开户,不能取款");
}else{
System.out.println("请输入取款金额");
Scanner input2 = new Scanner(System.in);
String bb = input2.next();
if(Double.parseDouble(bb) > card.getMoney() ){
System.out.println("余额不足");
}else{
card.setMoney(card.getMoney() - Double.parseDouble(bb) );
System.out.println("取款成功,取款金额"+bb+"余额是:"+card.getMoney());
}
}
}
}
}
这个是我简单写的逻辑,看你的需求应该就是这样,没有牵扯到数据库。。运行效果如图:
需要源码的话你把邮箱发给我,具体逻辑你还需要自己再修改一下,我只是把基本功能写出来了,还有开户操作我还没写,我只是把1这个用户默认成开户状态了。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯