JAVA基础第六天
2015-06-28 20:13
549 查看
单用户ATM模拟程序:
import javax.swing.JOptionPane;
public class ATM {
public static int money =8000; //银行卡里面现有的金额为8000
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "欢迎光临,工商银行");
boolean land = denglu();{
if(land==false){
JOptionPane.showMessageDialog(null, "非法用户");
System.exit(0);
}
}
while(true){
String s =JOptionPane.showInputDialog(null,"1、存款"+"\n"+"2、取款"+"\n"+"3、查询余额"+"\n"+"4、取卡");
int item =Integer.parseInt(s);
switch (item) {
case 1:
cunkuan();
break;
case 2:
qukuan();
break;
case 3:
cxye();
break;
case 4:
JOptionPane.showMessageDialog(null, "谢谢使用");
System.exit(0);
break;
default:
JOptionPane.showMessageDialog(null, "非法输入,请输入1-4");
break;
}
}
}
/*
* 登陆框
* 登陆是否成功
* */
public static boolean denglu(){
for(int i=0;i<3;i++){
String card =JOptionPane.showInputDialog(null,"请输入卡号");
String psw = JOptionPane.showInputDialog(null,"请输入密码");
if(card.equals("123456")&& psw.equals("aaaaaa")){
return true;
}
}
return false;
}
/*
* 查询余额
* */
public static void cxye(){
JOptionPane.showMessageDialog(null, "账号余额:"+money);
}
/*
* 存款
* */
public static void cunkuan(){
String x = JOptionPane.showInputDialog(null,"请输入存入的金额:");
int m = Integer.parseInt(x);
money = money+m;
String str =JOptionPane.showInputDialog(null, "是否显示余额? y/n");
if(str.equals("y")){
cxye();
}
}
/*
* 取款
* */
public static void qukuan(){
String y =JOptionPane.showInputDialog(null,"请输入取款金额");
int s =Integer.parseInt(y);
if(money<s){
JOptionPane.showMessageDialog(null, "余额不足,请重新输入");
}
else{
money =money -s;
String str =JOptionPane.showInputDialog(null, "是否显示余额?y/n");
if(str.equals("y")){
cxye();
}
}
}
}
2、多用户ATM机模拟程序:
import javax.swing.JOptionPane;
public class DyhATM {
public static String[] code ={"123456","21323","23256","12313"};
public static String[] pwd ={"aaa","bbb","ccc","ddd"};
public static int[] money={5000,6000,4000,2000};
//记录用户登陆系统的下标
public static int c=-1;
public static void main(String[] aaa){
JOptionPane.showMessageDialog(null, "欢迎光临,工商银行");
denglu();
if(c==-1){
JOptionPane.showMessageDialog(null, "非法用户");
System.exit(0);
}
while(true){
String s =JOptionPane.showInputDialog(null,"1、存款"+"\n"+"2、取款"+"\n"+"3、查询余额"+"\n"+"4、取卡");
int item =Integer.parseInt(s);
switch (item) {
case 1:
cunkuan();
break;
case 2:
qukuan();
break;
case 3:
cxye();
break;
case 4:
JOptionPane.showMessageDialog(null, "谢谢使用");
System.exit(0);
break;
default:
JOptionPane.showMessageDialog(null, "非法输入,请输入1-4");
break;
}
}
}
//登陆界面
public static void denglu(){
for(int i=0;i<3;i++){
String a =JOptionPane.showInputDialog(null,"请输入卡号");
String b = JOptionPane.showInputDialog(null,"请输入密码");
for(int x=0;x<code.length;x++){
if(a.equals(code[x]) && b.equals(pwd[x])){
c=x;
return;
}
}
}
}
//查询界面
public static void cxye(){
JOptionPane.showMessageDialog(null, "账号余额:"+money[c]);
}
//存款界面
public static void cunkuan(){
String x = JOptionPane.showInputDialog(null,"请输入存入的金额:");
int m = Integer.parseInt(x);
money[c] = money[c]+m;
String str =JOptionPane.showInputDialog(null, "是否显示余额? y/n");
if(str.equals("y")){
cxye();
}
}
public static void qukuan(){
String y =JOptionPane.showInputDialog(null,"请输入取款金额");
int s =Integer.parseInt(y);
if(money[c]<s){
JOptionPane.showMessageDialog(null, "余额不足,请重新输入");
}
else{
money[c] =money[c] -s;
String str =JOptionPane.showInputDialog(null, "是否显示余额?y/n");
if(str.equals("y")){
cxye();
}
}
}
}
import javax.swing.JOptionPane;
public class ATM {
public static int money =8000; //银行卡里面现有的金额为8000
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "欢迎光临,工商银行");
boolean land = denglu();{
if(land==false){
JOptionPane.showMessageDialog(null, "非法用户");
System.exit(0);
}
}
while(true){
String s =JOptionPane.showInputDialog(null,"1、存款"+"\n"+"2、取款"+"\n"+"3、查询余额"+"\n"+"4、取卡");
int item =Integer.parseInt(s);
switch (item) {
case 1:
cunkuan();
break;
case 2:
qukuan();
break;
case 3:
cxye();
break;
case 4:
JOptionPane.showMessageDialog(null, "谢谢使用");
System.exit(0);
break;
default:
JOptionPane.showMessageDialog(null, "非法输入,请输入1-4");
break;
}
}
}
/*
* 登陆框
* 登陆是否成功
* */
public static boolean denglu(){
for(int i=0;i<3;i++){
String card =JOptionPane.showInputDialog(null,"请输入卡号");
String psw = JOptionPane.showInputDialog(null,"请输入密码");
if(card.equals("123456")&& psw.equals("aaaaaa")){
return true;
}
}
return false;
}
/*
* 查询余额
* */
public static void cxye(){
JOptionPane.showMessageDialog(null, "账号余额:"+money);
}
/*
* 存款
* */
public static void cunkuan(){
String x = JOptionPane.showInputDialog(null,"请输入存入的金额:");
int m = Integer.parseInt(x);
money = money+m;
String str =JOptionPane.showInputDialog(null, "是否显示余额? y/n");
if(str.equals("y")){
cxye();
}
}
/*
* 取款
* */
public static void qukuan(){
String y =JOptionPane.showInputDialog(null,"请输入取款金额");
int s =Integer.parseInt(y);
if(money<s){
JOptionPane.showMessageDialog(null, "余额不足,请重新输入");
}
else{
money =money -s;
String str =JOptionPane.showInputDialog(null, "是否显示余额?y/n");
if(str.equals("y")){
cxye();
}
}
}
}
2、多用户ATM机模拟程序:
import javax.swing.JOptionPane;
public class DyhATM {
public static String[] code ={"123456","21323","23256","12313"};
public static String[] pwd ={"aaa","bbb","ccc","ddd"};
public static int[] money={5000,6000,4000,2000};
//记录用户登陆系统的下标
public static int c=-1;
public static void main(String[] aaa){
JOptionPane.showMessageDialog(null, "欢迎光临,工商银行");
denglu();
if(c==-1){
JOptionPane.showMessageDialog(null, "非法用户");
System.exit(0);
}
while(true){
String s =JOptionPane.showInputDialog(null,"1、存款"+"\n"+"2、取款"+"\n"+"3、查询余额"+"\n"+"4、取卡");
int item =Integer.parseInt(s);
switch (item) {
case 1:
cunkuan();
break;
case 2:
qukuan();
break;
case 3:
cxye();
break;
case 4:
JOptionPane.showMessageDialog(null, "谢谢使用");
System.exit(0);
break;
default:
JOptionPane.showMessageDialog(null, "非法输入,请输入1-4");
break;
}
}
}
//登陆界面
public static void denglu(){
for(int i=0;i<3;i++){
String a =JOptionPane.showInputDialog(null,"请输入卡号");
String b = JOptionPane.showInputDialog(null,"请输入密码");
for(int x=0;x<code.length;x++){
if(a.equals(code[x]) && b.equals(pwd[x])){
c=x;
return;
}
}
}
}
//查询界面
public static void cxye(){
JOptionPane.showMessageDialog(null, "账号余额:"+money[c]);
}
//存款界面
public static void cunkuan(){
String x = JOptionPane.showInputDialog(null,"请输入存入的金额:");
int m = Integer.parseInt(x);
money[c] = money[c]+m;
String str =JOptionPane.showInputDialog(null, "是否显示余额? y/n");
if(str.equals("y")){
cxye();
}
}
public static void qukuan(){
String y =JOptionPane.showInputDialog(null,"请输入取款金额");
int s =Integer.parseInt(y);
if(money[c]<s){
JOptionPane.showMessageDialog(null, "余额不足,请重新输入");
}
else{
money[c] =money[c] -s;
String str =JOptionPane.showInputDialog(null, "是否显示余额?y/n");
if(str.equals("y")){
cxye();
}
}
}
}
相关文章推荐
- SpringMvc+Jdbc泛型反射BaseDao
- spring jedisTemplate操作出现key和value值出现\xac字符
- 浅析Java中的final关键字(转)
- Java判断一个字符串是否是数字
- 1007--Java 时间和日期类型的 Hibernate 映射
- 【JAVA基础】-继承与接口
- dubbo分线程池处理同一服务请求随记
- java实现二维码([带]logo)的绘制和解析(zxing by google)
- 初识 javase(下)
- 【JAVA基础】-异常处理机制
- java内存分配和String类型的深度解析
- 根据wsdl生成java客户端
- equals和==比较
- java自带线程池和队列详细讲解
- Java集合汇总(一)
- JAVA记忆翻牌游戏制作
- spring bean的作用域
- Java中Iterator与Iterable的区别
- 学习笔记_Java_day12_设计模式MVC(13).JavaWeb的三层框架(14)
- Java判断文件、文件夹是否存在