java编程题,求思路和代码。做了一个多钟了还是没想法。

如题所述

第1个回答  2016-12-10
import java.text.DecimalFormat;
import java.util.Scanner;
public class Account {
private int temp; // 存储找到的ID
// 用户账号
private String account[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8","9" };
// 用户账户余额
private double money[] = { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 };
// 验证账户
private boolean isTrueAccount(String input) {
for (int i = 0; i < account.length; i++) {
if (input.equalsIgnoreCase(account[i])) {
temp = i;
break;
} else if (!input.equalsIgnoreCase(account[i])) {
return false;
}
}
return true;
}
//查询账户余额
private double showMoney() {
return money[temp];
}
//存入金额
private void incomeMoney() {
double num;
try {
System.out.println("Please enter money:");
num = new Scanner(System.in).nextDouble();
if (num < 0) {
System.out.println("The money mast more than zero!");
incomeMoney();
} else {
money[temp] += num;
}
} catch (Exception e) {
System.out.println("Input erro!");
incomeMoney();
}
}
//取钱方法
private void getMoney() {
double num;
try {
System.out.println("Please enter money:");
num = new Scanner(System.in).nextDouble();
if (num < 0) {
System.out.println("The money must more than zero!");
getMoney();
} else {
if (showMoney() < num) {
System.out.println("Balance money must more than zero!");
} else {
money[temp] -= num;
}
}
} catch (Exception e) {
System.out.println("Input erro!");
getMoney();
}
}
//显示主菜单
private void showMenu() {
String choose;
System.out.println("Main menu");
System.out.println("1: check balance");
System.out.println("2: withdraw");
System.out.println("3: deposit");
System.out.println("4: exit");
System.out.print("Enter a choice:");
choose = new Scanner(System.in).next();
if (choose.equals("1")) {
System.out.println("The balance is"
+ new DecimalFormat("0.0").format(showMoney()));
} else if (choose.equals("2")) {
incomeMoney();
showMenu();
} else if (choose.equals("3")) {
getMoney();
showMenu();
} else if (choose.equals("4")) {
System.out.println("Blance is Exit!");
System.out.println(" ");
showMenu();
} else {
System.out.println("Enter erro!");
showMenu();
}
}
// 输入账户
public void inputAccount() {
String id;
System.out.print("Enter an id:");
id = new Scanner(System.in).next();
if (isTrueAccount(id)) {
showMenu();
} else {
System.out.println("Id erro!");
inputAccount();
}
}
}
第2个回答  2016-12-10
···你先把9.7练习题 发上来追问

追答

···有字数的限制 

= = 

两个类都在里面了

本回答被提问者采纳