第三阶段Blog作业
题目集7-1 图形卡片排序游戏
输入格式:
- 首先,在一行上输入一串数字(1~4,整数),其中,1代表圆形卡片,2代表矩形卡片,3代表三角形卡片,4代表梯形卡片。各数字之间以一个或多个空格分隔,以“0”结束。例如: 1 3 4 2 1 3 4 2 1 3 0
- 然后根据第一行数字所代表的卡片图形类型,依次输入各图形的相关参数,例如:圆形卡片需要输入圆的半径,矩形卡片需要输入矩形的宽和长,三角形卡片需要输入三角形的三条边长,梯形需要输入梯形的上底、下底以及高。各数据之间用一个或多个空格分隔。
- 如果图形数量非法(小于0)或图形属性值非法(数值小于0以及三角形三边不能组成三角形),则输出Wrong Format。
- 如果输入合法,则正常输出,所有数值计算后均保留小数点后两位即可。输出内容如下:
输出格式:
- 排序前的各图形类型及面积,格式为图形名称1:面积值1图形名称2:面积值2 …图形名称n:面积值n ,注意,各图形输出之间用空格分开,且输出最后存在一个用于分隔的空格;
- 排序后的各图形类型及面积,格式同排序前的输出;
- 所有图形的面积总和,格式为Sum of area:总面积值。
输入样例1:
在这里给出一组输入。例如:
1 5 3 2 0
结尾无空行
输出样例1:
在这里给出相应的输出。例如:
Wrong Format
结尾无空行
输入样例2:
在这里给出一组输入。例如:
4 2 1 3 0
3.2 2.5 0.4 2.3 1.4 5.6 2.3 4.2 3.5
结尾无空行
输出样例2:
在这里给出相应的输出。例如:
The original list:
Trapezoid:1.14 Rectangle:3.22 Circle:98.52 Triangle:4.02
The sorted list:
Circle:98.52 Triangle:4.02 Rectangle:3.22 Trapezoid:1.14
Sum of area:106.91
结尾无空行
输入样例3:
在这里给出一组输入。例如:
4 2 1 3 0
3.2 2.5 0.4 2.3 1.4 5.6 2.3 4.2 8.4
结尾无空行
输出样例3:
在这里给出相应的输出。例如:
Wrong Format
结尾无空行
代码
import java.util.Scanner;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] A=new int[100];
int a=in.nextInt();
int x=0;
while(a!=0){
if(a>4 ||a<0){
System.out.print("Wrong Format");
System.exit(-1);
}
A[x]=a;
a=in.nextInt();
x++;
}
double[] B=new double[x];
int j=0;
for(int i=0;i<x;i++){
switch (A[i]){
case 1:
double radius=in.nextDouble();
if (radius <= 0){
System.out.print("Wrong Format");
System.exit(-1);//输入错误,直接结束;
}
Circle circle = new Circle();
circle.setRadius(radius);
B[j]=circle.getArea();
j++;
break;
case 2:
double width=in.nextDouble();
double length=in.nextDouble();
if (length <= 0 || width <= 0){
System.out.print("Wrong Format");
System.exit(-1);
}
Rectangle rectangle = new Rectangle();
rectangle.setLength(length);
rectangle.setWidth(width);
B[j]=rectangle.getArea();
j++;
break;
case 3:
double side1=in.nextDouble();
double side2=in.nextDouble();
double side3=in.nextDouble();
if (side1+side2<=side3 ||side1+side3<=side2 || side2+side3<=side1 || side1<=0 || side2<=0 || side3<=0){
System.out.print("Wrong Format");
System.exit(-1);
}
Triangle triangle= new Triangle();
triangle.setSide1(side1);
triangle.setSide2(side2);
triangle.setSide3(side3);
B[j]=triangle.getArea();
j++;
break;
case 4:
double side4=in.nextDouble();
double side5=in.nextDouble();
double height=in.nextDouble();
if (side4<=0 || side5<=0 || height<=0){
System.out.print("Wrong Format");
System.exit(0);
}
Trapezoid trapezoid= new Trapezoid();
trapezoid.setSide4(side4);
trapezoid.setSide5(side5);
trapezoid.setHeight(height);
B[j]=trapezoid.getArea();
j++;
break;
}
}
System.out.println("The original list:");
double sum=0;
for(int i=0;i<x;i++){
if(A[i]==1){
System.out.print("Circle:");
}
if(A[i]==2){
System.out.print("Rectangle:");
}
if(A[i]==3){
System.out.print("Triangle:");
}
if(A[i]==4){
System.out.print("Trapezoid:");
}
System.out.printf("%.2f ",B[i]);
sum+=B[i];
}
System.out.println("\nThe sorted list:");
double news;
int News;
for(int i=0;i<x;i++){
for(int k=0;k<x-1;k++){
if(B[k]>B[k+1]){
news=B[k];
B[k]=B[k+1];
B[k+1]=news;
News=A[k];
A[k]=A[k+1];
A[k+1]=News;
}
}
}
for(int i=x-1;i>=0;i--){
if(A[i]==1){
System.out.print("Circle:");
}
if(A[i]==2){
System.out.print("Rectangle:");
}
if(A[i]==3){
System.out.print("Triangle:");
}
if(A[i]==4){
System.out.print("Trapezoid:");
}
System.out.printf("%.2f ",B[i]);
}
System.out.printf("\nSum of area:%.2f",sum);
}
}
class Shape{
public double getArea(){
return 0.0;
}
}
class Circle extends Shape{//求圆面积
private double radius;
public double getRadius(){
return radius;
}
public void setRadius(double radius){
this.radius = radius;
}
public boolean validate(double radius){
return radius>0;
}
public double getArea(){
return Math.pow(radius,2)* Math.PI;
}
}
class Rectangle extends Shape{//求矩形面积
private double width;
private double length;
public double getWidth(){
return width;
}
public void setWidth(double width){
this.width = width;
}
public double getLength(){
return length;
}
public void setLength(double length) {
this.length = length;
}
public double getArea(){
return width * length;
}
}
class Triangle extends Shape{//求三角形面积
private double side1;
private double side2;
private double side3;
public double getSide1(){
return side1;
}
public void setSide1(double side1) {
this.side1 = side1;
}
public double getSide2(){
return side2;
}
public void setSide2(double side2) {
this.side2 = side2;
}
public double getSide3(){
return side3;
}
public void setSide3(double side3) {
this.side3 = side3;
}
public boolean validate(double side1,double side2,double side3){
return side1+side2>side3;
}
public double getArea(){
return (1.0/4.0)*Math.sqrt((side1+side2+side3)*(side1+side2-side3)*(side1+side3-side2)*(side2+side3-side1));
}
}
class Trapezoid extends Shape{
private double side4;
private double side5;
private double height;
public double getSide4(){
return side4;
}
public void setSide4(double side4) {
this.side4 = side4;
}
public double getSide5(){
return side5;
}
public void setSide5(double side5) {
this.side5 = side5;
}
public double getHeight(){
return height;
}
public void setHeight(double height) {
this.height = height;
}
public double getArea(){
return (1.0/2.0)*(side4+side5)*height;
}
}
分析

这道题没有想象中那么复杂,和前面有一次的图形继承差不多,只是在原来的基础上增加了在输入输出上的难度,也将每个图形都分好了类,没有特别的地方。
题目集7-2 图形卡片分组游戏
输入格式:
- 在一行上输入一串数字(1~4,整数),其中,1代表圆形卡片,2代表矩形卡片,3代表三角形卡片,4代表梯形卡片。各数字之间以一个或多个空格分隔,以“0”结束。例如:1 3 4 2 1 3 4 2 1 3 0
- 根据第一行数字所代表的卡片图形类型,依次输入各图形的相关参数,例如:圆形卡片需要输入圆的半径,矩形卡片需要输入矩形的宽和长,三角形卡片需要输入三角形的三条边长,梯形需要输入梯形的上底、下底以及高。各数据之间用一个或多个空格分隔。
- 如果图形数量非法(<=0)或图形属性值非法(数值<0以及三角形三边不能组成三角形),则输出Wrong Format。
- 如果输入合法,则正常输出,所有数值计算后均保留小数点后两位即可。输出内容如下:
输出格式:
- 排序前的各图形类型及面积,格式为[图形名称1:面积值1图形名称2:面积值2 …图形名称n:面积值n ],注意,各图形输出之间用空格分开,且输出最后存在一个用于分隔的空格,在结束符“]”之前;
- 输出分组后的图形类型及面积,格式为[圆形分组各图形类型及面积][矩形分组各图形类型及面积][三角形分组各图形类型及面积][梯形分组各图形类型及面积],各组内格式为图形名称:面积值。按照“Circle、Rectangle、Triangle、Trapezoid”的顺序依次输出;
- 各组内图形排序后的各图形类型及面积,格式同排序前各组图形的输出;
- 各组中面积之和的最大值输出,格式为The max area:面积值。
输入样例1:
在这里给出一组输入。例如:
1 5 3 2 0
结尾无空行
输出样例1:
在这里给出相应的输出。例如:
Wrong Format
结尾无空行
输入样例2:
在这里给出一组输入。例如:
4 2 1 3 0
3.2 2.5 0.4 2.3 1.4 5.6 2.3 4.2 3.5
结尾无空行
输出样例2:
在这里给出相应的输出。例如:
The original list:
[Trapezoid:1.14 Rectangle:3.22 Circle:98.52 Triangle:4.02 ]
The Separated List:
[Circle:98.52 ][Rectangle:3.22 ][Triangle:4.02 ][Trapezoid:1.14 ]
The Separated sorted List:
[Circle:98.52 ][Rectangle:3.22 ][Triangle:4.02 ][Trapezoid:1.14 ]
The max area:98.52
结尾无空行
输入样例3:
在这里给出一组输入。例如:
2 1 2 1 1 3 3 4 4 1 1 1 2 1 0
2.3 3.5 2.5 4.5 2.1 2.6 8.5 3.2 3.1 3.6 8.5 7.5 9.1245 6.5 3.4 10.2 11.2 11.6 15.4 5.8 2.13 6.2011 2.5 6.4 18.65
结尾无空行
输出样例3:
在这里给出相应的输出。例如:
The original list:
[Rectangle:8.05 Circle:19.63 Rectangle:9.45 Circle:21.24 Circle:226.98 Triangle:4.65 Triangle:29.80 Trapezoid:50.49 Trapezoid:175.56 Circle:105.68 Circle:14.25 Circle:120.81 Rectangle:16.00 Circle:1092.72 ]
The Separated List:
[Circle:19.63 Circle:21.24 Circle:226.98 Circle:105.68 Circle:14.25 Circle:120.81 Circle:1092.72 ][Rectangle:8.05 Rectangle:9.45 Rectangle:16.00 ][Triangle:4.65 Triangle:29.80 ][Trapezoid:50.49 Trapezoid:175.56 ]
The Separated sorted List:
[Circle:1092.72 Circle:226.98 Circle:120.81 Circle:105.68 Circle:21.24 Circle:19.63 Circle:14.25 ][Rectangle:16.00 Rectangle:9.45 Rectangle:8.05 ][Triangle:29.80 Triangle:4.65 ][Trapezoid:175.56 Trapezoid:50.49 ]
The max area:1601.31
结尾无空行
输入样例4:
在这里给出一组输入。例如:
1 1 3 0
6.5 12.54 3.6 5.3 6.4
结尾无空行
输出样例4:
在这里给出相应的输出。例如:
The original list:
[Circle:132.73 Circle:494.02 Triangle:9.54 ]
The Separated List:
[Circle:132.73 Circle:494.02 ][][Triangle:9.54 ][]
The Separated sorted List:
[Circle:494.02 Circle:132.73 ][][Triangle:9.54 ][]
The max area:626.75
结尾无空行
代码
import java.util.Scanner;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] A=new int[100];
int a=in.nextInt();
int x=0;
if(a==0){
System.out.print("Wrong Format");
System.exit(-1);
}
while(a!=0){
if(a>4 || a<0){
System.out.print("Wrong Format");
System.exit(-1);
}
A[x]=a;
a=in.nextInt();
x++;
}
double[] B=new double[x];
double[] Circle=new double[100];
double[] Rectangle=new double[100];
double[] Triangle=new double[100];
double[] Trapezoid=new double[100];
int j=0;
int c=0;
int v=0;
int n=0;
int m=0;
double sum1=0;
double sum2=0;
double sum3=0;
double sum4=0;
for(int i=0;i<x;i++){
switch (A[i]){
case 1:
double radius=in.nextDouble();
if (radius <= 0){
System.out.print("Wrong Format");
System.exit(-1);//输入错误,直接结束;
}
Circle circle = new Circle();
circle.setRadius(radius);
Circle[c]=circle.getArea();
B[j]=circle.getArea();
c++;
j++;
break;
case 2:
double width=in.nextDouble();
double length=in.nextDouble();
if (length <= 0 || width <= 0){
System.out.print("Wrong Format");
System.exit(-1);
}
Rectangle rectangle = new Rectangle();
rectangle.setLength(length);
rectangle.setWidth(width);
Rectangle[v]=rectangle.getArea();
B[j]=rectangle.getArea();
v++;
j++;
break;
case 3:
double side1=in.nextDouble();
double side2=in.nextDouble();
double side3=in.nextDouble();
if (side1+side2<=side3 ||side1+side3<=side2 || side2+side3<=side1 || side1<=0 || side2<=0 || side3<=0){
System.out.print("Wrong Format");
System.exit(-1);
}
Triangle triangle= new Triangle();
triangle.setSide1(side1);
triangle.setSide2(side2);
triangle.setSide3(side3);
Triangle[n]=triangle.getArea();
B[j]=triangle.getArea();
n++;
j++;
break;
case 4:
double side4=in.nextDouble();
double side5=in.nextDouble();
double height=in.nextDouble();
if (side4<=0 || side5<=0 || height<=0){
System.out.print("Wrong Format");
System.exit(-1);
}
Trapezoid trapezoid= new Trapezoid();
trapezoid.setSide4(side4);
trapezoid.setSide5(side5);
trapezoid.setHeight(height);
Trapezoid[m]=trapezoid.getArea();
B[j]=trapezoid.getArea();
m++;
j++;
break;
}
}
System.out.println("The original list:");
System.out.print("[");
for(int i=0;i<x;i++){
if(A[i]==1){
System.out.print("Circle:");
}
if(A[i]==2){
System.out.print("Rectangle:");
}
if(A[i]==3){
System.out.print("Triangle:");
}
if(A[i]==4){
System.out.print("Trapezoid:");
}
System.out.printf("%.2f ",B[i]);
}
System.out.print("]");
System.out.println("\nThe Separated List:");
System.out.print("[");
for(int i=0;i<c;i++){
System.out.printf("Circle:%.2f ",Circle[i]);
}
System.out.print("]");
System.out.print("[");
for(int i=0;i<v;i++){
System.out.printf("Rectangle:%.2f ",Rectangle[i]);
}
System.out.print("]");
System.out.print("[");
for(int i=0;i<n;i++){
System.out.printf("Triangle:%.2f ",Triangle[i]);
}
System.out.print("]");
System.out.print("[");
for(int i=0;i<m;i++){
System.out.printf("Trapezoid:%.2f ",Trapezoid[i]);
}
System.out.print("]");
System.out.println("\nThe Separated sorted List:");
double news;
for(int i=0;i<c;i++){
for(int k=0;k<c-1;k++){
if(Circle[k]>Circle[k+1]){
news=Circle[k];
Circle[k]=Circle[k+1];
Circle[k+1]=news;
}
}
}
for(int i=0;i<v;i++){
for(int k=0;k<v-1;k++){
if(Rectangle[k]>Rectangle[k+1]){
news=Rectangle[k];
Rectangle[k]=Rectangle[k+1];
Rectangle[k+1]=news;
}
}
}
for(int i=0;i<n;i++){
for(int k=0;k<n-1;k++){
if(Triangle[k]>Triangle[k+1]){
news=Triangle[k];
Triangle[k]=Triangle[k+1];
Triangle[k+1]=news;
}
}
}
for(int i=0;i<m;i++){
for(int k=0;k<m-1;k++){
if(Trapezoid[k]>Trapezoid[k+1]){
news=Trapezoid[k];
Trapezoid[k]=Trapezoid[k+1];
Trapezoid[k+1]=news;
}
}
}
System.out.print("[");
for(int i=c-1;i>=0;i--){
System.out.printf("Circle:%.2f ",Circle[i]);
sum1+=Circle[i];
}
System.out.print("]");
System.out.print("[");
for(int i=v-1;i>=0;i--){
System.out.printf("Rectangle:%.2f ",Rectangle[i]);
sum2+=Rectangle[i];
}
System.out.print("]");
System.out.print("[");
for(int i=n-1;i>=0;i--){
System.out.printf("Triangle:%.2f ",Triangle[i]);
sum3+=Triangle[i];
}
System.out.print("]");
System.out.print("[");
for(int i=m-1;i>=0;i--){
System.out.printf("Trapezoid:%.2f ",Trapezoid[i]);
sum4+=Trapezoid[i];
}
System.out.print("]");
double SUM = Math.max(sum1, Math.max(sum2, Math.max(sum3, sum4)));
System.out.printf("\nThe max area:%.2f",SUM);
}
}
class Shape{
public double getArea(){
return 0.0;
}
}
class Circle extends Shape{//求圆面积
private double radius;
public double getRadius(){
return radius;
}
public void setRadius(double radius){
this.radius = radius;
}
public boolean validate(double radius){
return radius>0;
}
public double getArea(){
return Math.pow(radius,2)* Math.PI;
}
}
class Rectangle extends Shape{//求矩形面积
private double width;
private double length;
public double getWidth(){
return width;
}
public void setWidth(double width){
this.width = width;
}
public double getLength(){
return length;
}
public void setLength(double length) {
this.length = length;
}
public double getArea(){
return width * length;
}
}
class Triangle extends Shape{//求三角形面积
private double side1;
private double side2;
private double side3;
public double getSide1(){
return side1;
}
public void setSide1(double side1) {
this.side1 = side1;
}
public double getSide2(){
return side2;
}
public void setSide2(double side2) {
this.side2 = side2;
}
public double getSide3(){
return side3;
}
public void setSide3(double side3) {
this.side3 = side3;
}
public boolean validate(double side1,double side2,double side3){
return side1+side2>side3;
}
public double getArea(){
return (1.0/4.0)*Math.sqrt((side1+side2+side3)*(side1+side2-side3)*(side1+side3-side2)*(side2+side3-side1));
}
}
class Trapezoid extends Shape{
private double side4;
private double side5;
private double height;
public double getSide4(){
return side4;
}
public void setSide4(double side4) {
this.side4 = side4;
}
public double getSide5(){
return side5;
}
public void setSide5(double side5) {
this.side5 = side5;
}
public double getHeight(){
return height;
}
public void setHeight(double height) {
this.height = height;
}
public double getArea(){
return (1.0/2.0)*(side4+side5)*height;
}
}
分析

这道题在前面的那题的基础上没有太大改动,加入了分组元素,每个图形组的输入输出都归结到一起,其实也没有那么复杂,因为有前面的基础写起来还是很容易的。
题目集8 ATM机类结构设计(一)
输入格式:
每一行输入一次业务操作,可以输入多行,最终以字符#终止。具体每种业务操作输入格式如下:
- 存款、取款功能输入数据格式: 卡号 密码 ATM机编号 金额(由一个或多个空格分隔), 其中,当金额大于0时,代表取款,否则代表存款。
- 查询余额功能输入数据格式: 卡号
输出格式:
①输入错误处理
- 如果输入卡号不存在,则输出Sorry,this card does not exist.。
- 如果输入ATM机编号不存在,则输出Sorry,the ATM's id is wrong.。
- 如果输入银行卡密码错误,则输出Sorry,your password is wrong.。
- 如果输入取款金额大于账户余额,则输出Sorry,your account balance is insufficient.。
- 如果检测为跨行存取款,则输出Sorry,cross-bank withdrawal is not supported.。
②取款业务输出
输出共两行,格式分别为:
[用户姓名]在[银行名称]的[ATM编号]上取款¥[金额]
当前余额为¥[金额]
其中,[]说明括起来的部分为输出属性或变量,金额均保留两位小数。
③存款业务输出
输出共两行,格式分别为:
[用户姓名]在[银行名称]的[ATM编号]上存款¥[金额]
当前余额为¥[金额]
其中,[]说明括起来的部分为输出属性或变量,金额均保留两位小数。
④查询余额业务输出
¥[金额]
金额保留两位小数。
输入样例1:
在这里给出一组输入。例如:
6222081502001312390 88888888 06 -500.00
#
结尾无空行
输出样例1:
在这里给出相应的输出。例如:
张无忌在中国工商银行的06号ATM机上存款¥500.00
当前余额为¥10500.00
结尾无空行
输入样例2:
在这里给出一组输入。例如:
6217000010041315709 88888888 02 3500.00
#
结尾无空行
输出样例2:
在这里给出相应的输出。例如:
杨过在中国建设银行的02号ATM机上取款¥3500.00
当前余额为¥6500.00
结尾无空行
输入样例3:
在这里给出一组输入。例如:
6217000010041315715
#
结尾无空行
输出样例3:
在这里给出相应的输出。例如:
¥10000.00
结尾无空行
输入样例4:
在这里给出一组输入。例如:
6222081502001312390 88888888 06 -500.00
6222081502051320786 88888888 06 1200.00
6217000010041315715 88888888 02 1500.00
6217000010041315709 88888888 02 3500.00
6217000010041315715
#
结尾无空行
输出样例4:
在这里给出相应的输出。例如:
张无忌在中国工商银行的06号ATM机上存款¥500.00
当前余额为¥10500.00
韦小宝在中国工商银行的06号ATM机上取款¥1200.00
当前余额为¥8800.00
杨过在中国建设银行的02号ATM机上取款¥1500.00
当前余额为¥8500.00
杨过在中国建设银行的02号ATM机上取款¥3500.00
当前余额为¥5000.00
¥5000.00
结尾无空行
代码
import java.util.Scanner;
import java.util.ArrayList;
class Account {
ArrayList<Bank> banklist;
private String name;
private String account;
private String password;
private double balance;
Bank bank;
private ArrayList<String> cardList;
public Account(){
}
public Account(String name,String account,String password,double balance,ArrayList<Bank> banklist,Bank bank,ArrayList<String> cardList){
this.name=name;
this.account=account;
this.password=password;
this.balance=balance;
this.bank=bank;
this.banklist=banklist;
this.cardList=cardList;
}
public String getName() {
return name;
}
public String getAccount() {
return account;
}
public String getPassword() {
return password;
}
public double getBalance() {
return balance;
}
public ArrayList<String> getCardList() {
return cardList;
}
public void setBalance(double balance) {
this.balance = balance;
}
}
class Bank {
ArrayList<String> ATMList;
String bankname;
public Bank(String bankname,ArrayList<String> ATMList)
{
this.bankname=bankname;
this.ATMList=ATMList;
}
}
class Check {
ArrayList<Account> accountList;
String card;
String password;
String number;
double money;
public Check(ArrayList<Account> accountList,String card,String password,String number,double money){
this.accountList=accountList;
this.card=card;
this.password=password;
this.number=number;
this.money=money;
}
public boolean check(){
int flag=0;
int k=0;
for(int i=0;i<accountList.size();i++){
for(int j=0;j<accountList.get(i).getCardList().size();j++){
if (card.equals(accountList.get(i).getCardList().get(j))){
flag=1;
k=i;
break;
}
}
if(flag==1){
break;
}
}
if(flag==1){
if(password.equals(accountList.get(k).getPassword())){
flag=2;
}
else{
System.out.print("Sorry,your password is wrong.");
return false;
}
}
else{
System.out.print("Sorry,this card does not exist.");
return false;
}
for(int i=0;i<accountList.get(k).banklist.size();i++){
for(int j=0;j<accountList.get(k).banklist.get(i).ATMList.size();j++){
if(number.equals(accountList.get(k).banklist.get(i).ATMList.get(j))){
flag=3;
break;
}
}
}
if(flag==3){
if(money<=accountList.get(k).getBalance()){
flag=4;
}
else{
System.out.print("Sorry,your account balance is insufficient.");
return false;
}
}
else{
System.out.print("Sorry,the ATM's id is wrong.");
return false;
}
for(int i=0;i<accountList.get(k).bank.ATMList.size();i++){
if(number.equals(accountList.get(k).bank.ATMList.get(i))){
flag=5;
break;
}
}
if(flag!=5){
System.out.print("Sorry,cross-bank withdrawal is not supported.");
return false;
}
return true;
}
public Check(ArrayList<Account> accountList, String card){
this.accountList = accountList;
this.card = card;
}
public boolean check1(){
int flag=0;
for (Account account : accountList) {
for (int j = 0; j < account.getCardList().size(); j++) {
if (card.equals(account.getCardList().get(j))) {
flag = 1;
break;
}
}
if (flag == 1) {
break;
}
}
if(flag!=1)
{
System.out.print("Sorry,this card does not exist.");
return false;
}
return true;
}
}
class Show{
ArrayList<Account> accountList;
String card;
String password;
String number;
double money;
public Show(ArrayList<Account> accountList,String card,String password,String number,double money){
this.password=password;
this.number=number;
this.card=card;
this.accountList=accountList;
this.money=money;
}
public void show(){
int t=0;
for(int i=0;i<accountList.size();i++){
for(int j=0;j<accountList.get(i).getCardList().size();j++){
if(card.equals(accountList.get(i).getCardList().get(j))){
t=i;
break;
}
}
}
if(money<0){
money=-money;
System.out.printf(accountList.get(t).getName()+"在"+accountList.get(t).bank.bankname+"的"+number+"号ATM机上存款¥%.2f\n",money);
}
else{
System.out.printf(accountList.get(t).getName()+"在"+accountList.get(t).bank.bankname+"的"+number+"号ATM机上取款¥%.2f\n",money);
}
System.out.printf("当前余额为¥%.2f\n",accountList.get(t).getBalance());
}
public Show(ArrayList<Account> accountList,String card){
this.accountList=accountList;
this.card=card;
}
public void show1(){
int t=0;
for(int i=0;i<accountList.size();i++){
for(int j=0;j<accountList.get(i).getCardList().size();j++){
if(card.equals(accountList.get(i).getCardList().get(j))){
t=i;
break;
}
}
}
System.out.printf("¥%.2f\n",accountList.get(t).getBalance());
}
}
public class Main {
public static void main(String[] args) {
ArrayList<String> ATMList1 = new ArrayList<>();
ArrayList<Bank> bankList = new ArrayList<>();
ATMList1.add("01");
ATMList1.add("02");
ATMList1.add("03");
ATMList1.add("04");
Bank jsyh = new Bank("中国建设银行", ATMList1);
bankList.add(jsyh);
ArrayList<String> ATMList2 = new ArrayList<>();
ATMList2.add("05");
ATMList2.add("06");
Bank gsyh = new Bank("中国工商银行", ATMList2);
bankList.add(gsyh);
ArrayList<String> cardList1 = new ArrayList<>();
ArrayList<Account> accountList = new ArrayList<>();
cardList1.add("6217000010041315709");
cardList1.add("6217000010041315715");
Account account1 = new Account("杨过", "3217000010041315709", "88888888", 10000.00, bankList, jsyh,cardList1);
accountList.add(account1);
ArrayList<String> cardList2 = new ArrayList<>();
cardList2.add("6217000010041315718");
Account account2 = new Account("杨过", "3217000010041315715", "88888888", 10000.00, bankList,jsyh,cardList2);
accountList.add(account2);
ArrayList<String> cardList3 = new ArrayList<>();
cardList3.add("6217000010051320007");
Account account3 = new Account("郭靖", "3217000010051320007", "88888888", 10000.00, bankList,jsyh,cardList3);
accountList.add(account3);
ArrayList<String> cardList4 = new ArrayList<>();
cardList4.add("6222081502001312389");
Account account4 = new Account("张无忌", "3222081502001312389", "88888888", 10000.00, bankList,gsyh,cardList4);
accountList.add(account4);
ArrayList<String> cardList5 = new ArrayList<>();
cardList5.add("6222081502001312390");
Account account5 = new Account("张无忌", "3222081502001312390", "88888888", 10000.00, bankList,gsyh,cardList5);
accountList.add(account5);
ArrayList<String> cardList6 = new ArrayList<>();
cardList6.add("6222081502001312399");
cardList6.add("6222081502001312400");
Account account6 = new Account("张无忌", "3222081502001312399", "88888888", 10000.00, bankList,gsyh,cardList6);
accountList.add(account6);
ArrayList<String> cardList7 = new ArrayList<>();
cardList7.add("6222081502051320785");
Account account7 = new Account("韦小宝", "3222081502051320785", "88888888", 10000.00, bankList,gsyh,cardList7);
accountList.add(account7);
ArrayList<String> cardList8 = new ArrayList<>();
cardList8.add("6222081502051320786");
Account account8 = new Account("韦小宝", "3222081502051320786", "88888888", 10000.00, bankList,gsyh,cardList8);
accountList.add(account8);
Scanner in=new Scanner(System.in);
String kp=in.nextLine();
Check check;
while(!kp.equals("#")){
String[] S=kp.split("\\s+");
if(S.length!=1){
check = new Check(accountList,S[0],S[1],S[2],Double.parseDouble(S[3]));
if (check.check()){
int t=0;
for(int i=0;i<accountList.size();i++){
for(int j=0;j<accountList.get(i).getCardList().size();j++){
if(S[0].equals(accountList.get(i).getCardList().get(j))){
t=i;
break;
}
}
}
accountList.get(t).setBalance(accountList.get(t).getBalance()-Double.parseDouble(S[3]));
Show show = new Show(accountList,S[0], S[1],S[2],Double.parseDouble(S[3]));
show.show();
}
}
else {
check=new Check(accountList,S[0]);
if(check.check1()){
Show show1= new Show(accountList,S[0]);
show1.show1();
}
}
kp=in.nextLine();
}
}
}
分析

这道题有点棘手,好在之前做过一个银行取钱的题目,用户账户也很大程度的得到进一步的扩展,没有做过这方面的深入,刚开始做起来还是很困难的,所以在使用类方法的时候没有考虑很多,很多地方都有更简便的算法,后来也没有纠结那么多。
题目集9 ATM机类结构设计(二)
输入格式:
每一行输入一次业务操作,可以输入多行,最终以字符#终止。具体每种业务操作输入格式如下:
- 取款功能输入数据格式: 卡号 密码 ATM机编号 金额(由一个或多个空格分隔)
- 查询余额功能输入数据格式: 卡号
输出格式:
①输入错误处理
- 如果输入卡号不存在,则输出Sorry,this card does not exist.。
- 如果输入ATM机编号不存在,则输出Sorry,the ATM's id is wrong.。
- 如果输入银行卡密码错误,则输出Sorry,your password is wrong.。
- 如果输入取款金额大于账户余额,则输出Sorry,your account balance is insufficient.。
②取款业务输出
输出共两行,格式分别为:
业务:取款 [用户姓名]在[银行名称]的[ATM编号]上取款¥[金额]
当前余额为¥[金额]
其中,[]说明括起来的部分为输出属性或变量,金额均保留两位小数。
③查询余额业务输出
业务:查询余额 ¥[金额]
金额保留两位小数。
输入样例1:
在这里给出一组输入。例如:
6222081502001312390 88888888 06 500.00
#
结尾无空行
输出样例1:
在这里给出相应的输出。例如:
业务:取款 张无忌在中国工商银行的06号ATM机上取款¥500.00
当前余额为¥9500.00
结尾无空行
输入样例2:
在这里给出一组输入。例如:
6217000010041315709 88888888 06 3500.00
#
结尾无空行
输出样例2:
在这里给出相应的输出。例如:
业务:取款 杨过在中国工商银行的06号ATM机上取款¥3500.00
当前余额为¥6395.00
结尾无空行
输入样例3:
在这里给出一组输入。例如:
6217000010041315715
#
结尾无空行
输出样例3:
在这里给出相应的输出。例如:
业务:查询余额 ¥10000.00
结尾无空行
输入样例4:
在这里给出一组输入。例如:
6222081502001312390 88888888 01 500.00
6222081502051320786 88888888 06 1200.00
6217000010041315715 88888888 02 1500.00
6217000010041315709 88888888 02 3500.00
6217000010041315715
#
结尾无空行
输出样例4:
在这里给出相应的输出。例如:
业务:取款 张无忌在中国建设银行的01号ATM机上取款¥500.00
当前余额为¥9490.00
业务:取款 韦小宝在中国工商银行的06号ATM机上取款¥1200.00
当前余额为¥8800.00
业务:取款 杨过在中国建设银行的02号ATM机上取款¥1500.00
当前余额为¥8500.00
业务:取款 杨过在中国建设银行的02号ATM机上取款¥3500.00
当前余额为¥5000.00
业务:查询余额 ¥5000.00
结尾无空行
输入样例5:
在这里给出一组输入。例如:
6640000010045442002 88888888 09 3000
6640000010045442002 88888888 06 8000
6640000010045442003 88888888 01 10000
6640000010045442002
#
结尾无空行
输出样例5:
在这里给出相应的输出。例如:
业务:取款 张三丰在中国农业银行的09号ATM机上取款¥3000.00
当前余额为¥6880.00
业务:取款 张三丰在中国工商银行的06号ATM机上取款¥8000.00
当前余额为¥-1416.00
业务:取款 张三丰在中国建设银行的01号ATM机上取款¥10000.00
当前余额为¥-11916.00
业务:查询余额 ¥-11916.00
结尾无空行
代码:
import java.util.Scanner;
import java.util.ArrayList;
class Bank{
String bankname;
ArrayList<String> ATMList;
public Bank(String bankname,ArrayList<String> ATMList)
{this.bankname=bankname;
this.ATMList=ATMList;}}
class Account{
Bank bank;
private String name;private String password;private double balance;
ArrayList<Bank> banklist;
private ArrayList<String> cardList;private ArrayList<String> ATMList;private ArrayList<String> BanknameList;
public Account() {}
public Account(String name,String account,String password,double balance,ArrayList<Bank> banklist,Bank bank,ArrayList<String> cardList,ArrayList<String> ATMList,ArrayList<String> BanknameList){
this.name=name;
this.password=password;
this.balance=balance;
this.bank=bank;
this.banklist=banklist;
this.cardList=cardList;
this.ATMList=ATMList;
this.BanknameList=BanknameList;}
public String getName() {
return name;}
public String getPassword() {
return password;}
public double getBalance() {
return balance;}
public ArrayList<String> getCardList() {
return cardList;}
public ArrayList<String> getATMList() {
return ATMList;}
public ArrayList<String> getBanknameList() {
return BanknameList;}
public void setBalance(double balance) {
this.balance = balance;}}
class Check{
ArrayList<Account> accountList;ArrayList<Account> accountList1;String card;String password;String number;
double money;
public Check(ArrayList<Account> accountList,String card,String password,String number,double money){
this.accountList=accountList;this.card=card;this.password=password;this.number=number;this.money=money;}
public Check(ArrayList<Account> accountList, String card){
this.accountList = accountList;this.card = card;}
public Check(ArrayList<Account> accountList,ArrayList<Account> accountList1,String card,String password,String number,double money){
this.accountList=accountList;this.accountList1=accountList1;this.card=card;this.password=password;this.number=number;this.money=money;}
public boolean check(){
int flag=0,k=0;
for(int i=0;i<accountList.size();i++){
for(int j=0;j<accountList.get(i).getCardList().size();j++){
if (card.equals(accountList.get(i).getCardList().get(j))){
flag=1;k=i;break;}}
if(flag==1){
break;}}
if(flag==1){
if(password.equals(accountList.get(k).getPassword())) flag=2;
else{
System.out.println("Sorry,your password is wrong.");//银行卡密码错误
return false;}}
else{
System.out.println("Sorry,this card does not exist.");//卡号不存在
return false;}
if(flag!=2) System.exit(-1);
for(int i=0;i<accountList.get(k).banklist.size();i++){
for(int j=0;j<accountList.get(k).banklist.get(i).ATMList.size();j++){
if(number.equals(accountList.get(k).banklist.get(i).ATMList.get(j))){
flag=3;break;}}}
if(flag==3) return true;
else{
System.out.println("Sorry,the ATM's id is wrong.");//ATM机编号不存在
return false;}}
public boolean check1(){
int flag=0;
for (Account account : accountList) {
for (int j = 0; j < account.getCardList().size(); j++) {
if (card.equals(account.getCardList().get(j))) {
flag = 1;
break;}}
if (flag == 1) break;}
if(flag==1) return true;
else{
System.out.println("Sorry,this card does not exist.");//卡号不存在
return false;}}
public boolean check2(){
int k=0,flag=0;
for(int i=0;i<accountList.size();i++){
for(int j=0;j<accountList.get(i).getCardList().size();j++){
if (card.equals(accountList.get(i).getCardList().get(j))){
k=i;break;}}}
for(int i=0;i<accountList.get(k).bank.ATMList.size();i++){
if(number.equals(accountList.get(k).bank.ATMList.get(i))){
flag=1;break;}}
return flag != 1;}
public boolean check3(){
int flag=0;
for (Account account : accountList1) {
for (int j = 0; j < account.getCardList().size(); j++) {
if (card.equals(account.getCardList().get(j))) {
flag = 1;
break;}}}return flag == 1;}
public boolean check4() {
int k = 0;
for (int i = 0; i < accountList.size(); i++) {
for (int j = 0; j < accountList.get(i).getCardList().size(); j++) {
if (card.equals(accountList.get(i).getCardList().get(j))) {
k = i;
break;}}}if(money<=accountList.get(k).getBalance()){
return true;} else {
System.out.println("Sorry,your account balance is insufficient.");//取款金额大于账户余额
return false;}}}
class Access{
ArrayList<Account> accountList;String card;String password;String number;
double money;
public Access(ArrayList<Account> accountList,String card,String password,String number,double money){
this.password=password;this.number=number;this.card=card;this.accountList=accountList;this.money=money;}
public void access(){
int k=0;
for(int i=0;i<accountList.size();i++){
for(int j=0;j<accountList.get(i).getCardList().size();j++){
if(card.equals(accountList.get(i).getCardList().get(j))){
k=i;break;}}}
accountList.get(k).setBalance(accountList.get(k).getBalance()-money);}
public void access1(){
int k=0;double q=0;
for(int i=0;i<accountList.size();i++){
for(int j=0;j<accountList.get(i).getCardList().size();j++){
if(card.equals(accountList.get(i).getCardList().get(j))){
k=i;break;}}}
for(int i=0;i<accountList.get(k).getATMList().size();i++){
if(number.equals(accountList.get(k).getATMList().get(0))||number.equals(accountList.get(k).getATMList().get(1))||number.equals(accountList.get(k).getATMList().get(2))||number.equals(accountList.get(k).getATMList().get(3))){
q=money*0.02;
break;} else if (number.equals(accountList.get(k).getATMList().get(4))||number.equals(accountList.get(k).getATMList().get(5))){
q=money*0.03;
break;} else if(number.equals(accountList.get(k).getATMList().get(6))||number.equals(accountList.get(k).getATMList().get(7))||number.equals(accountList.get(k).getATMList().get(8))||number.equals(accountList.get(k).getATMList().get(9))||number.equals(accountList.get(k).getATMList().get(10))){
q=money*0.04;
break;}}
accountList.get(k).setBalance(accountList.get(k).getBalance()-money-q);}
public void access2(){
int k=0;double l;
for(int i=0;i<accountList.size();i++){
for(int j=0;j<accountList.get(i).getCardList().size();j++){
if(card.equals(accountList.get(i).getCardList().get(j))){
k=i;break;}}}
if(accountList.get(k).getBalance()>money&&accountList.get(k).getBalance()>0){
accountList.get(k).setBalance(accountList.get(k).getBalance()-money);}
else if(accountList.get(k).getBalance()<money&&accountList.get(k).getBalance()>0){
l=(money-accountList.get(k).getBalance())*0.05;
accountList.get(k).setBalance(accountList.get(k).getBalance()-money-l);}
else if(accountList.get(k).getBalance()<money&&accountList.get(k).getBalance()<=0){
l=money*0.05;
accountList.get(k).setBalance(accountList.get(k).getBalance()-money-l);}}
public void access3() {
int k = 0;
double l,q=0;
for (int i = 0; i < accountList.size(); i++) {
for (int j = 0; j < accountList.get(i).getCardList().size(); j++) {
if (card.equals(accountList.get(i).getCardList().get(j))) {
k = i;
break;}}}
for (int i = 0; i < accountList.get(k).getATMList().size(); i++) {
if (number.equals(accountList.get(k).getATMList().get(0)) || number.equals(accountList.get(k).getATMList().get(1)) || number.equals(accountList.get(k).getATMList().get(2)) || number.equals(accountList.get(k).getATMList().get(3))) {
q = money * 0.02;
break;} else if (number.equals(accountList.get(k).getATMList().get(4)) || number.equals(accountList.get(k).getATMList().get(5))) {
q = money * 0.03;
break;} else if (number.equals(accountList.get(k).getATMList().get(6)) || number.equals(accountList.get(k).getATMList().get(7)) || number.equals(accountList.get(k).getATMList().get(8)) || number.equals(accountList.get(k).getATMList().get(9)) || number.equals(accountList.get(k).getATMList().get(10))) {
q = money * 0.04;
break;}}
if (accountList.get(k).getBalance() >=money&&accountList.get(k).getBalance()>0) {
accountList.get(k).setBalance(accountList.get(k).getBalance() - money - q);}
else if(accountList.get(k).getBalance() <money&&accountList.get(k).getBalance()>0){
l = (money - accountList.get(k).getBalance()) * 0.05;
accountList.get(k).setBalance(accountList.get(k).getBalance() - money - l - q);}
else if(accountList.get(k).getBalance() <money&&accountList.get(k).getBalance()<=0){
l=money*0.05;
accountList.get(k).setBalance(accountList.get(k).getBalance() - money - l - q);}}}
class Show{
ArrayList<Account> accountList;
ArrayList<Account> accountList1;
String card;
String password;
String number;
double money;
public Show(ArrayList<Account> accountList,ArrayList<Account> accountList1,String card,String password,String number,double money){
this.accountList=accountList;this.accountList1=accountList1;this.card=card;this.password=password;this.number=number;this.money=money;}
public Show(ArrayList<Account> accountList,String card){
this.accountList=accountList;
this.card=card;}
public void show(){
int k=0;
String bankname="";
for(int i=0;i<accountList.size();i++){
for(int j=0;j<accountList.get(i).getCardList().size();j++){
if(card.equals(accountList.get(i).getCardList().get(j))){
k=i;break;}}}
for(int i=0;i<accountList.get(k).getATMList().size();i++){
if(number.equals(accountList.get(k).getATMList().get(0))||number.equals(accountList.get(k).getATMList().get(1))||number.equals(accountList.get(k).getATMList().get(2))||number.equals(accountList.get(k).getATMList().get(3))){
bankname=accountList.get(k).getBanknameList().get(0);
break;}
else if (number.equals(accountList.get(k).getATMList().get(4))||number.equals(accountList.get(k).getATMList().get(5))){
bankname=accountList.get(k).getBanknameList().get(1);
break;}
else if(number.equals(accountList.get(k).getATMList().get(6))||number.equals(accountList.get(k).getATMList().get(7))||number.equals(accountList.get(k).getATMList().get(8))||number.equals(accountList.get(k).getATMList().get(9))||number.equals(accountList.get(k).getATMList().get(10))){
bankname=accountList.get(k).getBanknameList().get(2);
break;}}
if(money>=0){//取款
if(accountList.get(k).getBalance()>=0){
System.out.printf("业务:取款 "+accountList.get(k).getName()+"在"+bankname+"的"+number+"号ATM机上取款¥%.2f\n",money);}
else {
System.out.println("Sorry,your account balance is insufficient.");//输入取款金额大于账户余额
System.exit(-1);}}
else{//存款
money=-money;
System.out.printf("业务:存款 "+accountList.get(k).getName()+"在"+accountList.get(k).bank.bankname+"的"+number+"号ATM机上存款¥%.2f\n",money);}
System.out.printf("当前余额为¥%.2f\n",accountList.get(k).getBalance());}
public void show1(){
int t=0;
for(int i=0;i<accountList.size();i++){
for(int j=0;j<accountList.get(i).getCardList().size();j++){
if(card.equals(accountList.get(i).getCardList().get(j))){
t=i;break;}}}
System.out.printf("业务:查询余额 ¥%.2f",accountList.get(t).getBalance());}
public void show2() {
int k = 0;
String bankname = "";
for (int i = 0; i < accountList.size(); i++) {
for (int j = 0; j < accountList.get(i).getCardList().size(); j++) {
if (card.equals(accountList.get(i).getCardList().get(j))) {
k = i;break;}}}
for (int i = 0; i < accountList.get(k).getATMList().size(); i++) {
if (number.equals(accountList.get(k).getATMList().get(0)) || number.equals(accountList.get(k).getATMList().get(1)) || number.equals(accountList.get(k).getATMList().get(2)) || number.equals(accountList.get(k).getATMList().get(3))) {
bankname = accountList.get(k).getBanknameList().get(0);
break;} else if (number.equals(accountList.get(k).getATMList().get(4)) || number.equals(accountList.get(k).getATMList().get(5))) {
bankname = accountList.get(k).getBanknameList().get(1);
break;} else if (number.equals(accountList.get(k).getATMList().get(6)) || number.equals(accountList.get(k).getATMList().get(7)) || number.equals(accountList.get(k).getATMList().get(8)) || number.equals(accountList.get(k).getATMList().get(9)) || number.equals(accountList.get(k).getATMList().get(10))) {
bankname = accountList.get(k).getBanknameList().get(2);
break;}}
if(money>=0){//取款
if(accountList.get(k).getBalance()>=(-50000)){
System.out.printf("业务:取款 "+accountList.get(k).getName()+"在"+bankname+"的"+number+"号ATM机上取款¥%.2f\n",money);} else {
System.out.println("Sorry,your account balance is insufficient.");//透支金额超过规定最大透支金额
System.exit(-1);}}
else{//存款
money=-money;System.out.printf("业务:存款 "+accountList.get(k).getName()+"在"+accountList.get(k).bank.bankname+"的"+number+"号ATM机上存款¥%.2f\n",money);}
System.out.printf("当前余额为¥%.2f\n",accountList.get(k).getBalance());}}
class Custom{
public Custom(){}}
public class Main {
public static void main(String[] args) {
ArrayList<String> ATMList1 = new ArrayList<>();ArrayList<Bank> bankList = new ArrayList<>();ArrayList<String> ATMList = new ArrayList<>();ArrayList<String> ATMList2 = new ArrayList<>();ArrayList<String> ATMList3 = new ArrayList<>();
ATMList1.add("01");ATMList1.add("02");ATMList1.add("03");ATMList1.add("04");
Bank jsyh = new Bank("中国建设银行", ATMList1);
bankList.add(jsyh);
ATMList2.add("05");ATMList2.add("06");
Bank gsyh = new Bank("中国工商银行", ATMList2);
bankList.add(gsyh);
ATMList3.add("07");ATMList3.add("08");ATMList3.add("09");ATMList3.add("10");ATMList3.add("11");
Bank nyyh = new Bank("中国农业银行", ATMList3);
bankList.add(nyyh);
ATMList.add("01");ATMList.add("02");ATMList.add("03");ATMList.add("04");ATMList.add("05");ATMList.add("06");ATMList.add("07");ATMList.add("08");ATMList.add("09");ATMList.add("10");ATMList.add("11");
ArrayList<String> banknameList = new ArrayList<>();
banknameList.add("中国建设银行");banknameList.add("中国工商银行");banknameList.add("中国农业银行");
ArrayList<String> cardList1 = new ArrayList<>();
ArrayList<Account> accountList = new ArrayList<>();ArrayList<Account> accountList1 = new ArrayList<>();
cardList1.add("6217000010041315709");cardList1.add("6217000010041315715");
Account account1 = new Account("杨过", "3217000010041315709", "88888888", 10000.00, bankList, jsyh, cardList1, ATMList, banknameList);
accountList.add(account1);
ArrayList<String> cardList2 = new ArrayList<>();
cardList2.add("6217000010041315718");
Account account2 = new Account("杨过", "3217000010041315715", "88888888", 10000.00, bankList, jsyh, cardList2, ATMList, banknameList);
accountList.add(account2);
ArrayList<String> cardList3 = new ArrayList<>();
cardList3.add("6217000010051320007");
Account account3 = new Account("郭靖", "3217000010051320007", "88888888", 10000.00, bankList, jsyh, cardList3, ATMList, banknameList);
accountList.add(account3);
ArrayList<String> cardList4 = new ArrayList<>();
cardList4.add("6222081502001312389");
Account account4 = new Account("张无忌", "3222081502001312389", "88888888", 10000.00, bankList, gsyh, cardList4, ATMList, banknameList);
accountList.add(account4);
ArrayList<String> cardList5 = new ArrayList<>();
cardList5.add("6222081502001312390");
Account account5 = new Account("张无忌", "3222081502001312390", "88888888", 10000.00, bankList, gsyh, cardList5, ATMList, banknameList);
accountList.add(account5);
ArrayList<String> cardList6 = new ArrayList<>();
cardList6.add("6222081502001312399");cardList6.add("6222081502001312400");
Account account6 = new Account("张无忌", "3222081502001312399", "88888888", 10000.00, bankList, gsyh, cardList6, ATMList, banknameList);
accountList.add(account6);
ArrayList<String> cardList7 = new ArrayList<>();
cardList7.add("6222081502051320785");
Account account7 = new Account("韦小宝", "3222081502051320785", "88888888", 10000.00, bankList, gsyh, cardList7, ATMList, banknameList);
accountList.add(account7);
ArrayList<String> cardList8 = new ArrayList<>();
cardList8.add("6222081502051320786");
Account account8 = new Account("韦小宝", "3222081502051320786", "88888888", 10000.00, bankList, gsyh, cardList8, ATMList, banknameList);
accountList.add(account8);
ArrayList<String> cardList9 = new ArrayList<>();
cardList9.add("6640000010045442002");cardList9.add("6640000010045442003");
Account account9 = new Account("张三丰", "3640000010045442002", "88888888", 10000.00, bankList, jsyh, cardList9, ATMList, banknameList);
accountList.add(account9);accountList1.add(account9);
ArrayList<String> cardList10 = new ArrayList<>();
cardList10.add("6640000010045441009");
Account account10 = new Account("令狐冲", "3640000010045441009", "88888888", 10000.00, bankList, gsyh, cardList10, ATMList, banknameList);
accountList.add(account10);accountList1.add(account10);
ArrayList<String> cardList11 = new ArrayList<>();
cardList11.add("6630000010033431001");
Account account11 = new Account("乔峰", "3630000010033431001", "88888888", 10000.00, bankList, nyyh, cardList11, ATMList, banknameList);
accountList.add(account11);accountList1.add(account11);
ArrayList<String> cardList12 = new ArrayList<>();
cardList12.add("6630000010033431008");
Account account12 = new Account("洪七公", "3630000010033431008", "88888888", 10000.00, bankList, nyyh, cardList12, ATMList, banknameList);
accountList.add(account12);accountList1.add(account12);
Scanner in = new Scanner(System.in);
String kp = in.nextLine();
Check check,check1,check2,check3,check4;
Custom custom;int C=0;
if(C!=0) System.exit(-1);
while (!kp.contains("#")) {
String[] shuju = kp.split("\\s+");
if (shuju.length != 1) {//存取款
check =check2=check4= new Check(accountList, shuju[0], shuju[1], shuju[2], Double.parseDouble(shuju[3]));
check3 = new Check(accountList, accountList1, shuju[0], shuju[1], shuju[2], Double.parseDouble(shuju[3]));
if (check.check()) {
if (check3.check3()) {//贷记账号
if (check2.check2()) {
Access access3 = new Access(accountList, shuju[0], shuju[1], shuju[2], Double.parseDouble(shuju[3]));
access3.access3();} else {//未跨行
Access access2 = new Access(accountList, shuju[0], shuju[1], shuju[2], Double.parseDouble(shuju[3]));
access2.access2();}
Show show2 = new Show(accountList, accountList1, shuju[0], shuju[1], shuju[2], Double.parseDouble(shuju[3]));
show2.show2();} else {//借记账号
if (check4.check4()) {//金额检查
if (check2.check2()) {//跨行
Access access1 = new Access(accountList, shuju[0], shuju[1], shuju[2], Double.parseDouble(shuju[3]));
access1.access1();} else {//未跨行
Access access = new Access(accountList, shuju[0], shuju[1], shuju[2], Double.parseDouble(shuju[3]));
access.access();}
Show show = new Show(accountList, accountList1, shuju[0], shuju[1], shuju[2], Double.parseDouble(shuju[3]));
show.show();}}}} else {//余额
check1 = new Check(accountList, shuju[0]);
if (check1.check1()) {
Show show1 = new Show(accountList, shuju[0]);
show1.show1();}}
kp = in.nextLine();}}}
分析:

和上一题基本相同,难度也有了一定提升,但是在上一题的基础上修改代码就容易很多了,和上一题相比这道题加入了账号种类,加入了借贷功能,也加入了一些用户数据,其他方面就没有太大改变。
浙公网安备 33010602011771号