ATM机java代码,求填满!急急急!!!在线等!!!
importjava.util.*;/***WriteadescriptionofclassAccounthere.**@author(yourname)*@versio...
import java.util.*;
/**
* Write a description of class Account here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Account
{
public static void main(String[] args)
{
int m = 0;
boolean existed = false;
while (true)
{
//显示主菜单
m = displayMenu();
switch (m)
{
case 1:
//使用Account存款功能
break;
case 2 :
//使用Account取款功能
break;
case 3:
//使用Account查询余额功能
break;
case 4:
//new Account
break;
case 5 :
//使用Account销户功能
break;
case 0:
existed = true;
break;
default:
//报错,提示重新输入
}
if (existed)
{
System.out.println("====================退出成功!!!====================");
break;
}
}
}
public static int displayMenu()
{
System.out.println("====================欢迎使用ATM自助机====================");
System.out.println("1 - 存款");
System.out.println("2 - 取款");
System.out.println("3 - 查询余额");
System.out.println("4 - 开户");
System.out.println("5 - 销户");
System.out.println("0 - 退出");
System.out.print("请选择:");
Scanner in = new Scanner(System.in);
int result = in.nextInt();
return result;
}
} 展开
/**
* Write a description of class Account here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Account
{
public static void main(String[] args)
{
int m = 0;
boolean existed = false;
while (true)
{
//显示主菜单
m = displayMenu();
switch (m)
{
case 1:
//使用Account存款功能
break;
case 2 :
//使用Account取款功能
break;
case 3:
//使用Account查询余额功能
break;
case 4:
//new Account
break;
case 5 :
//使用Account销户功能
break;
case 0:
existed = true;
break;
default:
//报错,提示重新输入
}
if (existed)
{
System.out.println("====================退出成功!!!====================");
break;
}
}
}
public static int displayMenu()
{
System.out.println("====================欢迎使用ATM自助机====================");
System.out.println("1 - 存款");
System.out.println("2 - 取款");
System.out.println("3 - 查询余额");
System.out.println("4 - 开户");
System.out.println("5 - 销户");
System.out.println("0 - 退出");
System.out.print("请选择:");
Scanner in = new Scanner(System.in);
int result = in.nextInt();
return result;
}
} 展开
1个回答
展开全部
import java.util.*;
/**
* Write a description of class Account here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Account {
public static void main(String[] args) {
int m = 0;
boolean existed = false;
int price = 0;
int flag = 0;
while (true) {
// 显示主菜单
m = displayMenu();
switch (m) {
case 1:
if (flag == 0) {
System.err.println("请先开户");
break;
}
// 使用Account存款功能
System.out.print("请输入存储的金额,必须是整数");
Scanner s = new Scanner(System.in);
int p = s.nextInt();
price = price + p;
System.err.println("您当前的余额是" + price);
break;
case 2:
// 使用Account取款功能
if (flag == 0) {
System.err.println("请先开户");
break;
}
System.out.print("请输入取储的金额,必须是整数");
Scanner s1 = new Scanner(System.in);
int p1 = s1.nextInt();
while (p1 > price) {
System.err.println("您的余额不足!请重新输入");
s1 = new Scanner(System.in);
p1 = s1.nextInt();
}
price = price - p1;
System.err.println("您当前的余额是" + price);
break;
case 3:
if (flag == 0) {
System.err.println("请先开户");
break;
}
// 使用Account查询余额功能
System.err.println("您当前的余额是" + price);
break;
case 4:
// new Account
price = 0;
flag = 1;
System.err.println("开户成功,当前余额为0元");
break;
case 5:
if (flag == 0) {
System.err.println("您还未开户");
break;
}
// 使用Account销户功能
price = 0;
flag = 0;
System.err.println("销户成功");
break;
case 0:
existed = true;
break;
default:
// 报错,提示重新输入
}
if (existed) {
System.out
.println("====================退出成功!!!====================");
break;
}
}
}
public static int displayMenu() {
System.out
.println("====================欢迎使用ATM自助机====================");
System.out.println("1 - 存款");
System.out.println("2 - 取款");
System.out.println("3 - 查询余额");
System.out.println("4 - 开户");
System.out.println("5 - 销户");
System.out.println("0 - 退出");
System.out.print("请选择:");
Scanner in = new Scanner(System.in);
int result = in.nextInt();
return result;
}
}
追问
我爱你
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询