package com.ziv.homework
import java.util.Scanner;
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String op = null; // 输入的操作命令
boolean bool = true; // 外成循環
String[][] user =new String[2][3];
int count = 0; // 當前用戶數量
int userid = -1; // 當前用戶登陸的id
String name=null,pwd=null;
double money ;
while(bool){
System.out.println("1.註冊,2.登陸,3.退出");
op = s.next();
switch (op) {
case "1":
if(count < 2){
while(true){
System.out.println("輸入用戶名:");
name = s.next();
if(name.length()>3&&name.length()<11){
user[count][0] = name;
System.out.println("添加成功");
break;
}else{
System.out.println("輸入錯誤必須在3-10之間!");
}
}
while(true){
System.out.println("請輸入密碼:");
pwd = s.next();
if(pwd.length() == 6){
user[count][1] = pwd;
user[count][2] = "";
count++;
System.out.println("添加成功");
break;
}else{
System.out.println("輸入錯誤密碼必須是6為");
}
}
}else{
System.out.println("註冊數量以賣弄");
}
break;
case "2":
System.out.println("輸入用戶名:");
name = s.next();
System.out.println("請輸入密碼:");
pwd = s.next();
for (int i = 0; i < user.length; i++) {
if(name.equals(user[i][0]) && pwd.equals(user[i][1])){
userid = i;
}
}
if(userid<0){
System.out.println("用戶不存在,重新登陸");
}else{
while(bool){
System.out.println("1.存錢\n2.取錢\n3.轉帳\n4.查詢\n5.密碼修改\n6.退出");
op = s.next();
switch (op) {
case "1":
System.out.println("存錢多少:");
if(user[userid][2] == "" || "".equals(user[userid][2]))
user[userid][2] = s.nextDouble() + "";
else
user[userid][2] = Double.parseDouble(user[userid][2]) + s.nextDouble() + "";
break;
case "2":
System.out.println("取多少錢");
double moneyIn= s.nextDouble();
money = Double.parseDouble(user[userid][2]);
if(moneyIn <= money){
user[userid][2] = money - moneyIn + "";
}else{
System.out.println("錢不夠,不能取");
}
break;
case "3":
while(true){
System.out.println("請輸入轉個誰:");
name = s.next();
if(name.equals(user[0][0]) || name.equals(user[1][0])){
System.out.println("輸入要轉的錢");
double moneyOut = s.nextDouble();
money = Double.parseDouble(user[userid][2]);
if(moneyOut <= money){
user[userid][2] = money - moneyOut + "";
int useridOther = 0;
if(userid == 0) useridOther = 1;
if(userid == 1) useridOther = 0;
if(user[useridOther][2] == "" || "".equals(user[useridOther][2]))
user[useridOther][2] = moneyOut + "";
else
user[useridOther][2] = Double.parseDouble(user[useridOther][2]) + moneyOut + "";
System.out.println("轉帳成功!");
break;
}else{
System.out.println("錢不夠,不能取");
}
}else{
System.out.println("用戶不在");
}
}
break;
case "4":
System.out.println("MONEY:" + user[userid][2]);
break;
case "5":
while(true){
System.out.println("請輸入密碼:");
pwd = s.next();
if(pwd.length() == 6){
user[userid][1] = pwd;
break;
}else{
System.out.println("輸入錯誤密碼必須是6為");
}
}
break;
case "6":
bool = false;
break;
default:
System.out.println("你輸入的命令有無");
break;
}
}
}
bool = true;
break;
case "3":
bool = false;
break;
default:
System.out.println("不要亂搞!,再來一次");
break;
}
}
}
}
import java.util.Scanner;
/*
1、ATM机
要求:
1)注册(两个):
用户名,密码,余额
在请输入用户名(英文),密码(数字,长度必须为6个长度),余额(double,必须大于10)。用一个数组装。
提示:注册成功。
否则失败。
2)登录,欢迎页面。
限制登录三次就被吃卡不能再次登录,提示还剩多少次登录机会(登录失败)
3)登录成功
1)查询余额
2)取款
3)转账
4)存钱
5)修改密码
6)退出
*/
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String op = null; // 输入的操作命令
boolean bool = true; // 外成循環
String[][] user =new String[2][3];
int count = 0; // 當前用戶數量
int userid = -1; // 當前用戶登陸的id
String name=null,pwd=null;
double money ;
while(bool){
System.out.println("1.註冊,2.登陸,3.退出");
op = s.next();
switch (op) {
case "1":
if(count < 2){
while(true){
System.out.println("輸入用戶名:");
name = s.next();
if(name.length()>3&&name.length()<11){
user[count][0] = name;
System.out.println("添加成功");
break;
}else{
System.out.println("輸入錯誤必須在3-10之間!");
}
}
while(true){
System.out.println("請輸入密碼:");
pwd = s.next();
if(pwd.length() == 6){
user[count][1] = pwd;
user[count][2] = "";
count++;
System.out.println("添加成功");
break;
}else{
System.out.println("輸入錯誤密碼必須是6為");
}
}
}else{
System.out.println("註冊數量以賣弄");
}
break;
case "2":
System.out.println("輸入用戶名:");
name = s.next();
System.out.println("請輸入密碼:");
pwd = s.next();
for (int i = 0; i < user.length; i++) {
if(name.equals(user[i][0]) && pwd.equals(user[i][1])){
userid = i;
}
}
if(userid<0){
System.out.println("用戶不存在,重新登陸");
}else{
while(bool){
System.out.println("1.存錢\n2.取錢\n3.轉帳\n4.查詢\n5.密碼修改\n6.退出");
op = s.next();
switch (op) {
case "1":
System.out.println("存錢多少:");
if(user[userid][2] == "" || "".equals(user[userid][2]))
user[userid][2] = s.nextDouble() + "";
else
user[userid][2] = Double.parseDouble(user[userid][2]) + s.nextDouble() + "";
break;
case "2":
System.out.println("取多少錢");
double moneyIn= s.nextDouble();
money = Double.parseDouble(user[userid][2]);
if(moneyIn <= money){
user[userid][2] = money - moneyIn + "";
}else{
System.out.println("錢不夠,不能取");
}
break;
case "3":
while(true){
System.out.println("請輸入轉個誰:");
name = s.next();
if(name.equals(user[0][0]) || name.equals(user[1][0])){
System.out.println("輸入要轉的錢");
double moneyOut = s.nextDouble();
money = Double.parseDouble(user[userid][2]);
if(moneyOut <= money){
user[userid][2] = money - moneyOut + "";
int useridOther = 0;
if(userid == 0) useridOther = 1;
if(userid == 1) useridOther = 0;
if(user[useridOther][2] == "" || "".equals(user[useridOther][2]))
user[useridOther][2] = moneyOut + "";
else
user[useridOther][2] = Double.parseDouble(user[useridOther][2]) + moneyOut + "";
System.out.println("轉帳成功!");
break;
}else{
System.out.println("錢不夠,不能取");
}
}else{
System.out.println("用戶不在");
}
}
break;
case "4":
System.out.println("MONEY:" + user[userid][2]);
break;
case "5":
while(true){
System.out.println("請輸入密碼:");
pwd = s.next();
if(pwd.length() == 6){
user[userid][1] = pwd;
break;
}else{
System.out.println("輸入錯誤密碼必須是6為");
}
}
break;
case "6":
bool = false;
break;
default:
System.out.println("你輸入的命令有無");
break;
}
}
}
bool = true;
break;
case "3":
bool = false;
break;
default:
System.out.println("不要亂搞!,再來一次");
break;
}
}
}
}