博客作业

第三次博客作业

图形卡片排序游戏

考点:类的继承,多态的使用,接口的应用
解题思路:输入采用在线做法,一边读入一边判断数据,通过case语句处理,如果超出1-4则输出Wrong Format,1-4则进行数据处理,矩阵属于梯形计算方法,因此可以直接用继承关系,梯形作为父类,case3时需要特判不是三角形的情况,先判断再跳转至计算,答案利用数组存储,先输出原数组,再进行排序,最后输出排序之后的数组
改进:可以增加图形加大复杂度

  • 测试数据1
    1 5 3 2 0
  • 输出样例1
    Wrong Format
  • 测试数据2
    4 2 1 3 0 3.2 2.5 0.4 2
  • 输出样例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

根据本题设计出类图如下所示:
image
以下为完整代码
`import java.util.Arrays;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeSet;
abstract class Shape{
private String ShapeName;
public Shape(){

}

public Shape(String ShapeName)
{
    this.ShapeName=ShapeName;
}

public String getShapeName()
{
    return ShapeName;
}

public void setShapeName(String ShapeName)
{
    this.ShapeName=ShapeName;
}
/*public  double getArea()
{
    return 0.0;
}
public boolean validate()
{
    return true;
}*/

public abstract double getArea();
public abstract boolean validate();


public String toString()
{
    return getShapeName()+":"+String.format("%.2f ",getArea());
}

}

class Card implements Comparable
{
private Shape shape;

public Card()
{

}

public Card(Shape shape)
{
    this.shape=shape;
}

public Shape getShape()
{
    return shape;
}

public void setShape(Shape shape)
{
    this.shape=shape;
}


@Override
public int compareTo(Card card)
{
    return -(int)(shape.getArea()-card.getShape().getArea());
}

}

class Circle extends Shape
{
private double Radius;
public Circle()
{

}
public Circle(double Radius)
{
    this.Radius=Radius;
}

public double getRadius()
{
    return Radius;
}

public void setRadius(double Radius)
{
    this.Radius=Radius;
}

@Override


public double getArea()
{
    return Math.PI*Radius*Radius;
}

@Override


public boolean validate()
{
    return Radius>0;
}

}

class Rectangle extends Shape
{

private double Width;
private double Length;

public Rectangle()
{

}


public Rectangle(double Width,double Length)
{
    this.Length=Length;
    this.Width=Width;


}

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;
}


@Override



public double getArea()
{
    return Width*Length;
}


@Override



public boolean  validate()
{
    return Width>0&&Length>0;
}

}

class Triangle extends Shape
{
private double a;
private double b;
private double c;

public Triangle()
{

}

public Triangle(double a,double b,double c)
{
    this.a=a;
    this.b=b;
    this.c=c;
}

public double getA()
{
    return a;
}

public void setA(double a)
{
    this.a=a;
}

public double getB()
{
    return b;
}

public void setB(double b)
{
    this.b=b;
}


public double getC()
{
    return c;
}

public void setC(double c)
{
    this.c=c;
}

@Override



public double getArea()
{
    double d=(a+b+c)/2;
    return Math.sqrt(d*(d-a)*(d-b)*(d-c));
}

@Override



public boolean validate()
{
    boolean t=true;
    if(!(a>0&&b>0&&c>0))
    {
        t= false;
    }
    else
    {
        if(!(a+b>c&&a+c>b&&b+c>a))
        {
            t=false;
        }
    }

    return t;
    //double[] arr=new double[3];
    //arr[0]=a;
    //arr[1]=b;
    //arr[2]=c;
    //Arrays.sort(arr);
    //return arr[0]+arr[1]>arr[2];
}

}

class Traperzoid extends Shape{
private double topSide;
private double bottomSide;
private double height;

Traperzoid(){

}


Traperzoid(double topSide,double bottomSide,double height){
    this.bottomSide=bottomSide;
    this.height=height;
    this.topSide=topSide;
}


public double getTopside()
{
    return topSide;
}


public void setTopSide(double topSide)
{
    this.topSide=topSide;
}


public double getBottomSide()
{
    return bottomSide;
}

public void setBottomSide()
{
    this.bottomSide=bottomSide;
}


public double getHeight()
{
    return height;
}

public void setHeight()
{
    this.height=height;
}


@Override


public double getArea()
{
    return (topSide+bottomSide)*height/2;
}


@Override


public boolean validate()
{
    return topSide>0&&bottomSide>0&&height>0;

}

}

public class Main{
public static Scanner input=new Scanner(System.in);
public static void main(String[] args){
ArrayList list=new ArrayList();
int n=input.nextInt();
while(n!=0)
{
if(n<0||n>4)
{
System.out.println("Wrong Format");
System.exit(0);
}
list.add(n);
n=input.nextInt();
}

    CardList cardList=new CardList(list);
    if(!cardList.validate())
    {
        System.out.println("Wrong Format");
        System.exit(0);
    }

    cardList.show();




}

}

class CardList{
ArrayList cardList=new ArrayList<>();

public CardList()
{

}

public CardList(ArrayList<Integer> card)
{
    for(Integer integer: card)
    {
        switch (integer)
        {
            case 1:
                double radius=Main.input.nextDouble();
                Circle circle=new Circle(radius);
                Card card1=new Card(circle);
                card1.getShape().setShapeName("Circle");
                cardList.add(card1);
                break;


            case 2:
                double w=Main.input.nextDouble();
                double l=Main.input.nextDouble();
                Rectangle rectangle=new Rectangle(w,l);
                Card card2=new Card(rectangle);
                card2.getShape().setShapeName("Rectangle");
                cardList.add(card2);
                break;



            case 3:
                double a=Main.input.nextDouble();
                double b=Main.input.nextDouble();
                double c=Main.input.nextDouble();
                Triangle triangle=new Triangle(a,b,c);
                Card card3=new Card(triangle);
                card3.getShape().setShapeName("Triangle");
                cardList.add(card3);
                break;


            case 4:
                double k=Main.input.nextDouble();
                double y=Main.input.nextDouble();
                double z=Main.input.nextDouble();
                Traperzoid traperzoid=new Traperzoid(k,y,z);
                Card card4=new Card(traperzoid);
                card4.getShape().setShapeName("Trapezoid");
                cardList.add(card4);
                break;


        }
    }


}

public boolean validate()//判断数据是否合法
{
    boolean t=true;
    for(Card card : cardList)
    {
        if(!card.getShape().validate())
        {
            t=false;
            break;
        }
    }

    return t;
}


public double getSum()//得到面积的总和
{
    double sum=0;
    for(Card card : cardList)
    {
        sum+=card.getShape().getArea();
    }

    return sum;
}


public void cardSort()//输出图形名字
{
    TreeSet<Card> cardSort =new TreeSet<>(cardList);
    for(Card card : cardSort)
    {
        System.out.print(card.getShape());
    }
}


public void show()//整体输出效果
{
    System.out.println("The original list:");
    for(Card card : cardList)
    {
        System.out.print(card.getShape());
    }

    System.out.println();
    System.out.println("The sorted list:");
    cardSort();
    System.out.println();
    System.out.printf("Sum of area:%.2f\n",getSum());
}

}

图形卡片分组游戏

考点:类的继承,多态的使用,接口的应用
解题思路:与第一题相似,但多出了类型判断,使用Arraylist等集合框架才能分组储存几个图形类,之后再进行求面积和排序等工作,首先输入采用在线做法,一边读入一边判断数据,通过case语句处理,如果超出1-4则输出Wrong Format,1-4则进行数据处理,矩阵属于梯形计算方法,因此可以直接用继承关系,梯形作为父类,case3时需要特判不是三角形的情况,先判断再跳转至计算,答案利用数组存储,先输出原数组,再进行排序,最后输出排序之后的数组,再循环求出面积最大值
改进:可以增加图形加大复杂度

  • 测试数据1
    1 5 3 2 0
  • 输出样例1
    Wrong Format
  • 测试数据2
    4 2 1 3 0 3.2 2.5 0.4 2
  • 输出样例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
    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.Arrays;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeSet;

abstract class Shape{
private String ShapeName;
public Shape(){

}

public Shape(String ShapeName)
{
    this.ShapeName=ShapeName;
}

public String getShapeName()
{
    return ShapeName;
}

public void setShapeName(String ShapeName)
{
    this.ShapeName=ShapeName;
}
/*public  double getArea()
{
    return 0.0;
}
public boolean validate()
{
    return true;
}*/

public abstract double getArea();
public abstract boolean validate();


public String toString()
{
    return getShapeName()+":"+String.format("%.2f ",getArea());
}

}

class Card implements Comparable
{
private Shape shape;

/*public Card()
{

}*/

public Card(Shape shape)
{
    this.shape=shape;
}

public Shape getShape()
{
    return shape;
}

public void setShape(Shape shape)
{
    this.shape=shape;
}


@Override
public int compareTo(Card card)
{
    return -(int)(shape.getArea()-card.getShape().getArea());
}

}

class Circle extends Shape
{
private double Radius;
public Circle()
{

}
public Circle(double Radius)
{
    this.Radius=Radius;
}

public double getRadius()
{
    return Radius;
}

public void setRadius(double Radius)
{
    this.Radius=Radius;
}

@Override


public double getArea()
{
    return Math.PI*Radius*Radius;
}

@Override


public boolean validate()
{
    return Radius>0;
}

}

class Rectangle extends Shape
{

private double Width;
private double Length;

public Rectangle()
{

}


public Rectangle(double Width,double Length)
{
    this.Length=Length;
    this.Width=Width;


}

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;
}


@Override



public double getArea()
{
    return Width*Length;
}


@Override



public boolean  validate()
{
    return Width>0&&Length>0;
}

}

class Triangle extends Shape
{
private double a;
private double b;
private double c;

public Triangle()
{

}

public Triangle(double a,double b,double c)
{
    this.a=a;
    this.b=b;
    this.c=c;
}

public double getA()
{
    return a;
}

public void setA(double a)
{
    this.a=a;
}

public double getB()
{
    return b;
}

public void setB(double b)
{
    this.b=b;
}


public double getC()
{
    return c;
}

public void setC(double c)
{
    this.c=c;
}

@Override



public double getArea()
{
    double d=(a+b+c)/2;
    return Math.sqrt(d*(d-a)*(d-b)*(d-c));
}

@Override



public boolean validate()
{
    boolean t=true;
    if(!(a>0&&b>0&&c>0))
    {
        t= false;
    }
    else
    {
        if(!(a+b>c&&a+c>b&&b+c>a))
        {
            t=false;
        }
    }

    return t;
}

}

class Traperzoid extends Shape{
private double topSide;
private double bottomSide;
private double height;

Traperzoid(){

}


Traperzoid(double topSide,double bottomSide,double height){
    this.bottomSide=bottomSide;
    this.height=height;
    this.topSide=topSide;
}
@Override


public double getArea()
{
    return (topSide+bottomSide)*height/2;
}


@Override


public boolean validate()
{
    return topSide>0&&bottomSide>0&&height>0;

}

}

public class Main{
public static Scanner input=new Scanner(System.in);
public static void main(String[] args){
ArrayList list=new ArrayList();
int n=input.nextInt();
if(n==0)
{
System.out.print("Wrong Format");
System.exit(0);
}
while(n!=0)
{
if(n<0||n>4)
{
System.out.print("Wrong Format");
System.exit(0);
}
list.add(n);
n=input.nextInt();
}

    CardList cardList=new CardList(list);
    if(!cardList.validate())
    {
        System.out.println("Wrong Format");
        System.exit(0);
    }

    cardList.show();




}

}

class CardList{
ArrayList cardList1=new ArrayList<>();
ArrayList cardList2=new ArrayList<>();
ArrayList cardList3=new ArrayList<>();
ArrayList cardList4=new ArrayList<>();
ArrayList cardList=new ArrayList<>();

public CardList()
{

}

public CardList(ArrayList<Integer> card)
{
    for(Integer integer: card)
    {
        switch (integer)
        {
            case 1:
                double radius=Main.input.nextDouble();
                Circle circle=new Circle(radius);
                Card card1=new Card(circle);
                card1.getShape().setShapeName("Circle");
                cardList1.add(card1);
                cardList.add(card1);
                break;


            case 2:
                double w=Main.input.nextDouble();
                double l=Main.input.nextDouble();
                Rectangle rectangle=new Rectangle(w,l);
                Card card2=new Card(rectangle);
                card2.getShape().setShapeName("Rectangle");
                cardList2.add(card2);
                cardList.add(card2);
                break;



            case 3:
                double a=Main.input.nextDouble();
                double b=Main.input.nextDouble();
                double c=Main.input.nextDouble();
                Triangle triangle=new Triangle(a,b,c);
                Card card3=new Card(triangle);
                card3.getShape().setShapeName("Triangle");
                cardList3.add(card3);
                cardList.add(card3);
                break;


            case 4:
                double k=Main.input.nextDouble();
                double y=Main.input.nextDouble();
                double z=Main.input.nextDouble();
                Traperzoid traperzoid=new Traperzoid(k,y,z);
                Card card4=new Card(traperzoid);
                card4.getShape().setShapeName("Trapezoid");
                cardList4.add(card4);
                cardList.add(card4);
                break;


        }
    }


}

public boolean validate()//判断数据是否合法
{
    boolean t=true;
    for(Card card : cardList)
    {
        if(!card.getShape().validate())
        {
            t=false;
            break;
        }
    }
    return t;
}



public double getMaxArea()
{
    double max1=0;
    double max2=0;
    double max3=0;
    double max4=0;
    double max=0;
    double[] d=new double[4];
    for(Card card : cardList1)
    {
         max1+=card.getShape().getArea();
    }
    d[0]=max1;
    for(Card card : cardList2)
    {
        max2+=card.getShape().getArea();
    }
    d[1]=max2;
    for(Card card : cardList3)
    {
        max3+=card.getShape().getArea();
    }
    d[2]=max3;
    for(Card card : cardList4)
    {
        max4+=card.getShape().getArea();
    }
    d[3]=max4;
    max=d[0];
    for(int i=1;i<=3;i++)
    {
        if(max<d[i])
        {
            max=d[i];
        }
    }

    return max;


}






public void cardSort()
{
    TreeSet<Card> cardSort1 =new TreeSet<>(cardList1);
    System.out.print("[");
    for(Card card : cardSort1)
    {
        System.out.print(card.getShape());
    }
    System.out.print("]");
    TreeSet<Card> cardSort2 =new TreeSet<>(cardList2);
    System.out.print("[");
    for(Card card : cardSort2)
    {
        System.out.print(card.getShape());
    }
    System.out.print("]");
    TreeSet<Card> cardSort3 =new TreeSet<>(cardList3);
    System.out.print("[");
    for(Card card : cardSort3)
    {
        System.out.print(card.getShape());
    }
    System.out.print("]");
    TreeSet<Card> cardSort4 =new TreeSet<>(cardList4);
    System.out.print("[");
    for(Card card : cardSort4)
    {
        System.out.print(card.getShape());
    }
    System.out.print("]");

}


public void show()
{
    System.out.println("The original list:");
    System.out.print("[");
    for(Card card : cardList)
    {
        System.out.print(card.getShape());
    }
    System.out.println("]");
    System.out.println("The Separated List:");
    System.out.print("[");
    for(Card card : cardList1)
    {
        System.out.print(card.getShape());
    }
    System.out.print("]");
    System.out.print("[");
    for(Card card : cardList2)
    {
        System.out.print(card.getShape());
    }
    System.out.print("]");
    System.out.print("[");
    for(Card card : cardList3)
    {
        System.out.print(card.getShape());
    }
    System.out.print("]");
    System.out.print("[");
    for(Card card : cardList4)
    {
        System.out.print(card.getShape());
    }
    System.out.print("]");

    System.out.println();
    System.out.println("The Separated sorted List:");
    cardSort();


    System.out.println();
    System.out.printf("The max area:%.2f\n",getMaxArea());
}

}`

ATM机类结构设计(一)

问题分析:本题要求编写一个银行ATM机的模拟程序,能够完成用户的存款、取款以及查询余额功能,需要分别设计银行类Bank,用户类User,卡类card,银联类UnionPay,机器类ATM,账户类Account之后设计好他们之间类与类之间的关系,其中以关联为主。

  • 测试数据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.text.DecimalFormat;
    import java.util.ArrayList;
    import java.util.Scanner;
    class Bank
    {
    String bankname;
    ArrayList ATMList;
    public Bank(String bankname,ArrayList ATMList)
    {
    this.bankname=bankname;
    this.ATMList=ATMList;
    }

}
class Account
{
private String name;
ArrayList banklist;
Bank bank;
private String account;
private String password;
private double balance;
private ArrayList cardList;
public Account(String name, ArrayList banklist,Bank bank,String account,String password,double balance,
ArrayList cardList)
{
this.bank=bank;
this.banklist=banklist;
this.name=name;
this.account=account;
this.password=password;
this.balance=balance;
this.cardList=cardList;
}

public void setName(String name) {
    this.name = name;
}

public String getName() {
    return name;
}

public void setAccount(String account) {
    this.account = account;
}

public String getAccount() {
    return account;
}

public void setPassword(String password) {
    this.password = password;
}

public String getPassword() {
    return password;
}

public void setBalance(double balance) {
    this.balance = balance;
}

public double getBalance() {
    return balance;
}

public void setCardList(ArrayList<String> cardList) {
    this.cardList = cardList;
}

public ArrayList<String> getCardList() {
    return cardList;
}

}
class Check2 {
ArrayList accountList;
String card;

public Check2(ArrayList<Account> accountList, String card) {
    this.accountList = accountList;
    this.card = card;
}

public boolean check() {
    int flag = 0;
    for (int j = 0; j < accountList.size(); j++) {
        for (int i = 0; i < accountList.get(j).getCardList().size(); i++) {
            if (card.compareTo(accountList.get(j).getCardList().get(i)) == 0)//卡号校验
            {
                flag = 1;
                break;
            }
        }
        if(flag==1)
            break;
    }
    if(flag==1)
        return true;
        else
    {
        System.out.println("Sorry,this card does not exist.");
        return false;

    }
}

}
class Check1
{
ArrayList accountList;
String card;
String password;
String number;
double money;
public Check1(ArrayList 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 t = 0;
//System.out.println(accountList.size());
for(int j=0;j<accountList.size();j++) {
for (int i = 0; i < accountList.get(j).getCardList().size(); i++) {
if (card.compareTo(accountList.get(j).getCardList().get(i)) == 0)//卡号校验
{
flag = 1;
t=j;
break;

            }
        }
        if(flag==1)
            break;
    }
    if(flag==1)
    {
         //password=password.replaceAll(" ","");
        if(password.compareTo(accountList.get(t).getPassword())==0)//密码校验
        {
            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)
    {
        for(int j=0;j<accountList.get(t).banklist.size();j++) {
            for (int i = 0; i < accountList.get(t).banklist.get(j).ATMList.size(); i++)     //ATM 机编号校验
                if (number.compareTo(accountList.get(t).banklist.get(j).ATMList.get(i)) == 0) {
                    flag = 3;
                    break;
                }
        }
    }
    if(flag==3)
    {
        if(money<=accountList.get(t).getBalance())   //金额校验
        {
            flag=4;
        }
        else {
            System.out.println("Sorry,your account balance is insufficient.");
            return false;
        }

    }
    else
    {
        System.out.println("Sorry,the ATM's id is wrong.");
        return false;

    }
    if(flag==4)
    {
        for(int i=0;i<accountList.get(t).bank.ATMList.size();i++) {
                    if (number.compareTo(accountList.get(t).bank.ATMList.get(i)) == 0) {
                        flag = 5;
                        break;
                }
            }
    }
    if(flag!=5) {
        System.out.println("Sorry,cross-bank withdrawal is not supported.");
        return false;
    }
        else
            return true;
    }

}
class Show
{
ArrayList accountList;
String card;
public Show(ArrayList accountList,String card)
{
this.accountList=accountList;
this.card=card;
}
public void show()
{
DecimalFormat df = new DecimalFormat("#.00");
int t=0;
for(int j=0;j<accountList.size();j++) {
for (int i = 0; i < accountList.get(j).getCardList().size(); i++) {
if (card.compareTo(accountList.get(j).getCardList().get(i)) == 0)//卡号校验
{
t=j;
break;

            }
        }
    }
    System.out.println("¥"+df.format(accountList.get(t).getBalance()));
}

}
class Access
{
ArrayList accountList;
String card;
String password;
String number;
double money;
public Access(ArrayList 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 t=0;
    for(int j=0;j<accountList.size();j++) {
        for (int i = 0; i < accountList.get(j).getCardList().size(); i++) {
            if (card.compareTo(accountList.get(j).getCardList().get(i)) == 0)//卡号校验
            {
                t=j;
                break;

            }
        }
    }
    if(money>=0)//取款
    {
        accountList.get(t).setBalance(accountList.get(t).getBalance()-money);
    }
    else//存款
    {
        accountList.get(t).setBalance(accountList.get(t).getBalance()-money);
    }
}
public void show()
{
    DecimalFormat df = new DecimalFormat("#.00");
    int t=0;
    for(int j=0;j<accountList.size();j++) {
        for (int i = 0; i < accountList.get(j).getCardList().size(); i++) {
            if (card.compareTo(accountList.get(j).getCardList().get(i)) == 0)//卡号校验
            {
                t=j;
                break;

            }
        }
    }
    if(money>=0)//取款
    {
        System.out.println(accountList.get(t).getName()+"在"+accountList.get(t).bank.bankname+"的"+number+"号ATM机上取款¥"+df.format(money));
        if(accountList.get(t).getBalance()==0)
            System.out.println("当前余额为¥0.00");
        else
            System.out.println("当前余额为¥"+df.format(accountList.get(t).getBalance()));
    }
    else
    {
        money=-money;
        System.out.println(accountList.get(t).getName()+"在"+accountList.get(t).bank.bankname+"的"+number+"号ATM机上存款¥"+df.format(money));
        System.out.println("当前余额为¥"+df.format(accountList.get(t).getBalance()));
    }
}

}

public class Main {
public static void main(String[] args) {
ArrayList ATMList1 = new ArrayList();
ATMList1.add("01");
ATMList1.add("02");
ATMList1.add("03");
ATMList1.add("04");
Bank bankjian = new Bank("中国建设银行", ATMList1);
ArrayList ATMList2 = new ArrayList();
ATMList2.add("05");
ATMList2.add("06");
Bank bankgong = new Bank("中国工商银行", ATMList2);

    ArrayList<Bank> bankList = new ArrayList<Bank>();
    bankList.add(bankjian);
    bankList.add(bankgong);

    ArrayList<String> cardList1 = new ArrayList<String>();
    cardList1.add("6217000010041315709");
    cardList1.add("6217000010041315715");
    Account account1 = new Account("杨过", bankList, bankjian, "3217000010041315709", "88888888", 10000.00, cardList1);

    ArrayList<String> cardList2 = new ArrayList<String>();
    cardList2.add("6217000010041315718");
    Account account2 = new Account("杨过", bankList, bankjian, "3217000010041315715", "88888888", 10000.00, cardList2);

    ArrayList<String> cardList3 = new ArrayList<String>();
    cardList3.add("6217000010051320007");
    Account account3 = new Account("郭靖", bankList, bankjian, "3217000010051320007", "88888888", 10000.00, cardList3);

    ArrayList<String> cardList4 = new ArrayList<String>();
    cardList4.add("6222081502001312389");
    Account account4 = new Account("张无忌", bankList, bankgong, "3222081502001312389", "88888888", 10000.00, cardList4);

    ArrayList<String> cardList5 = new ArrayList<String>();
    cardList5.add("6222081502001312390");
    Account account5 = new Account("张无忌", bankList, bankgong, "3222081502001312390", "88888888", 10000.00, cardList5);

    ArrayList<String> cardList6 = new ArrayList<String>();
    cardList6.add("6222081502001312399");
    cardList6.add("6222081502001312400");
    Account account6 = new Account("张无忌", bankList, bankgong, "3222081502001312399", "88888888", 10000.00, cardList6);

    ArrayList<String> cardList7 = new ArrayList<String>();
    cardList7.add("6222081502051320785");
    Account account7 = new Account("韦小宝", bankList, bankgong, "3222081502051320785", "88888888", 10000.00, cardList7);

    ArrayList<String> cardList8 = new ArrayList<String>();
    cardList8.add("6222081502051320786");
    Account account8 = new Account("韦小宝", bankList, bankgong, "3222081502051320786", "88888888", 10000.00, cardList8);

    ArrayList<Account> accountList = new ArrayList<Account>();
    accountList.add(account1);
    accountList.add(account2);
    accountList.add(account3);
    accountList.add(account4);
    accountList.add(account5);
    accountList.add(account6);
    accountList.add(account7);
    accountList.add(account8);
    Scanner in = new Scanner(System.in);
    //卡号 密码 ATM 机编号 金额
    String abc = " ";
    Check1 check1 = null;
    Check2 check2 = null;
    abc=in.nextLine();
    while(abc.compareTo("#")!=0) {
        String[] shuju=abc.split(" ");
        ArrayList<String> list = new ArrayList<String>();
        for(int i =0;i<shuju.length;i++)
        {
            if(shuju[i].compareTo("")==0)
            {
                for(int j=i;j< shuju.length-1;j++)
                {
                    shuju[j]=shuju[j+1];
                }
            }
        }
        for(int i=0;i<shuju.length;i++)
        {
            if(shuju[i].compareTo("")==0)
                break;
            else
            list.add(shuju[i]);
        }

        if(list.size()!=1) {
            //System.out.println("ok");
            double money = Double.valueOf(shuju[3]);
            check1 = new Check1(accountList, list.get(0), list.get(1), list.get(2), money);
            if (check1.check()) {
                Access access = new Access(accountList, list.get(0), list.get(1), list.get(2), money);
                access.access();
                access.show();
            }
        }
        else if(list.size()==1)
        {
            check2 = new Check2(accountList,list.get(0));
            if(check2.check())
            {
                Show show= new Show(accountList, list.get(0));
                show.show();
            }

        }
        abc=in.nextLine();
    }
}
private static void insertionSort(int[] list) {
      for (int i = 1;i < list.length;i++)
        {
            int num = list[i];
            int j = i - 1;
            for (;j >= 0 && list[j] > num;j--)
            {
                list[j + 1] = list[j];
            }
            list[j + 1] = num;
        }

     
        }
        
  private static void selectionSort(int[] list) {
      for(int j=0;j<list.length-1;j++)
        {
            for(int i=j+1;i<list.length;i++)
            {
                if(list[j]>list[i])
                {
                    int t=list[j];
                    list[j]=list[i];
                    list[i]=t;
                }
              }
        }
        
    }
  private static void bubbleSort(int[] list) {
      for(int j=0;j<list.length-1;j++)
        {
            for(int i=0;i<list.length-1-j;i++)
            {
                if(list[i]>list[i+1])
                {
                    int t=list[i];
                    list[i]=list[i+1];
                    list[i+1]=t;
                }
            }
        }
        
    }

class DateUtil {
private int year;
private int month;
private int day;

public DateUtil(int year, int month, int day) {
    this.year = year;
    this.month = month;
    this.day = day;
}

public DateUtil(){}

public void setYear(int year) {
    this.year = year;
}

public void setMonth(int month) {
    this.month = month;
}

public void setDay(int day) {
    this.day = day;
}

public int getYear() {
    return year;
}

public int getMonth() {
    return month;
}

public int getDay() {
    return day;
}

}
}

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
  • 测试数据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.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Scanner;
class Bank
{
String bankname;
ArrayList < String > ATMList;
public Bank(String bankname, ArrayList < String > ATMList)
{
this.bankname = bankname;
this.ATMList = ATMList;
}
}
class Account
{
private String name;
ArrayList < Bank > banklist;
Bank bank;
private String account;
private String type;
private String password;
private double balance;
private ArrayList < String > cardList;
public Account(String name, ArrayList < Bank > banklist, Bank bank, String account, String type, String password, double balance, ArrayList < String > cardList)
{
this.bank = bank;
this.banklist = banklist;
this.name = name;
this.account = account;
this.password = password;
this.balance = balance;
this.cardList = cardList;
this.type = type;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setAccount(String account)
{
this.account = account;
}
public String getAccount()
{
return account;
}
public void setPassword(String password)
{
this.password = password;
}
public String getPassword()
{
return password;
}
public void setBalance(double balance)
{
this.balance = balance;
}
public double getBalance()
{
return balance;
}
public void setCardList(ArrayList < String > cardList)
{
this.cardList = cardList;
}
public ArrayList < String > getCardList()
{
return cardList;
}
public void setType(String type)
{
this.type = type;
}
public String getType()
{
return type;
}
}
class Check2
{
ArrayList < Account > accountList;
String card;
public Check2(ArrayList < Account > accountList, String card)
{
this.accountList = accountList;
this.card = card;
}
public boolean check()
{
int flag = 0;
for(int j = 0; j < accountList.size(); j++)
{
for(int i = 0; i < accountList.get(j).getCardList().size(); i++)
{
if(card.compareTo(accountList.get(j).getCardList().get(i)) == 0) //卡号校验
{
flag = 1;
break;
}
}
if(flag == 1) break;
}
if(flag == 1) return true;
else
{
System.out.println("Sorry,this card does not exist.");
return false;
}
}
}
class Check1
{
ArrayList < Account > accountList;
String card;
String password;
String number;
double money;
public Check1(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 t = 0;
//System.out.println(accountList.size());
for(int j = 0; j < accountList.size(); j++)
{
for(int i = 0; i < accountList.get(j).getCardList().size(); i++)
{
if(card.compareTo(accountList.get(j).getCardList().get(i)) == 0) //卡号校验
{
flag = 1;
t = j;
break;
}
}
if(flag == 1) break;
}
if(flag == 1)
{
//password=password.replaceAll(" ","");
if(password.compareTo(accountList.get(t).getPassword()) == 0) //密码校验
{
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)
{
for(int j = 0; j < accountList.get(t).banklist.size(); j++)
{
for(int i = 0; i < accountList.get(t).banklist.get(j).ATMList.size(); i++) //ATM 机编号校验
if(number.compareTo(accountList.get(t).banklist.get(j).ATMList.get(i)) == 0)
{
flag = 3;
break;
}
}
}
if(flag == 3)
{
if(accountList.get(t).getType().compareTo("借记账号") == 0)
{
if(money <= accountList.get(t).getBalance()) //金额校验
{
flag = 4;
}
else
{
System.out.println("Sorry,your account balance is insufficient.");
return false;
}
}
else if(accountList.get(t).getType().compareTo("贷记账号") == 0)
{
if(money <= accountList.get(t).getBalance() + 50000) //金额校验
{
flag = 4;
}
else
{
System.out.println("Sorry,your account balance is insufficient.");
return false;
}
}
}
else
{
System.out.println("Sorry,the ATM's id is wrong.");
return false;
}
return true;
}
}
class Show
{
ArrayList < Account > accountList;
String card;
public Show(ArrayList < Account > accountList, String card)
{
this.accountList = accountList;
this.card = card;
}
public void show()
{
DecimalFormat df = new DecimalFormat("#.00");
int t = 0;
for(int j = 0; j < accountList.size(); j++)
{
for(int i = 0; i < accountList.get(j).getCardList().size(); i++)
{
if(card.compareTo(accountList.get(j).getCardList().get(i)) == 0) //卡号校验
{
t = j;
break;
}
}
}
System.out.println("业务:查询余额" + " " + "¥" + df.format(accountList.get(t).getBalance()));
}
}
class Access
{
DecimalFormat df = new DecimalFormat("#.00");
ArrayList < Account > accountList;
ArrayList < Bank > bankList;
String name = null;
String card;
String password;
String number;
double money;
int t = 0;
int m = 0;
public Access(ArrayList < Account > accountList, ArrayList < Bank > bankList, String card, String password, String number, double money)
{
this.password = password;
this.number = number;
this.card = card;
this.accountList = accountList;
this.money = money;
this.bankList = bankList;
}
public void access()
{
for(int j = 0; j < accountList.size(); j++)
{
for(int i = 0; i < accountList.get(j).getCardList().size(); i++)
{
if(card.compareTo(accountList.get(j).getCardList().get(i)) == 0) //卡号校验
{
t = j;
break;
}
}
}
int flag = 0;
for(int i = 0; i < accountList.get(t).bank.ATMList.size(); i++)
{
if(number.compareTo(accountList.get(t).bank.ATMList.get(i)) == 0)
{
flag = 1; //不跨行
name = accountList.get(t).bank.bankname;
break;
}
}
if(flag != 1) //跨行
{
for(int i = 0; i < bankList.size(); i++)
{
for(int j = 0; j < bankList.get(i).ATMList.size(); j++)
{
if(number.compareTo(bankList.get(i).ATMList.get(j)) == 0)
{
name = bankList.get(i).bankname;
flag = 2;
break;
}
}
if(flag == 2) break;
}
}
if(accountList.get(t).getType().compareTo("借记账号") == 0)
{
if(flag == 1)
{ //不跨行
if(money >= 0) //取款
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money);
}
else //存款
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money);
}
}
if(flag == 2) //跨行
{
if(name.compareTo("中国建设银行") == 0)
{
if(money >= 0) //取款
{
if(accountList.get(t).getBalance() - money - money * 0.02 < 0)
{
System.out.println("Sorry,your account balance is insufficient.");
m = 1;
}
else
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money - money * 0.02);
}
}
else //存款
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money);
}
}
else if(name.compareTo("中国工商银行") == 0)
{
if(money >= 0) //取款
{
if(accountList.get(t).getBalance() - money - money * 0.03 < 0)
{
System.out.println("Sorry,your account balance is insufficient.");
m = 1;
}
else
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money - money * 0.03);
}
}
else //存款
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money);
}
}
else if(name.compareTo("中国农业银行") == 0)
{
if(money >= 0) //取款
{
if(accountList.get(t).getBalance() - money - money * 0.04 < 0)
{
System.out.println("Sorry,your account balance is insufficient.");
m = 1;
}
else
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money - money * 0.04);
}
}
else //存款
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money);
}
}
}
}
else if(accountList.get(t).getType().compareTo("贷记账号") == 0)
{
if(flag == 1)
{ //不跨行
if(money >= 0) //取款
{
if(money <= accountList.get(t).getBalance())
{ //未透支
if(accountList.get(t).getBalance() - money < -50000)
{
System.out.println("Sorry,your account balance is insufficient.");
m = 1;
}
else
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money);
}
}
else
{ //透支
if(accountList.get(t).getBalance() >= 0)
{
if(accountList.get(t).getBalance() - money - (money - accountList.get(t).getBalance()) * 0.05 < -50000)
{
System.out.println("Sorry,your account balance is insufficient.");
m = 1;
}
else
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money - (money - accountList.get(t).getBalance()) * 0.05);
}
}
else
{
if(accountList.get(t).getBalance() - money - (money * 0.05) < -50000)
{
System.out.println("Sorry,your account balance is insufficient.");
m = 1;
}
else
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money - (money * 0.05));
}
}
}
}
else //存款
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money);
}
}
if(flag == 2) //跨行
{
if(name.compareTo("中国建设银行") == 0)
{
if(money >= 0) //取款
{
if(money <= accountList.get(t).getBalance())
{ //未透支
if(accountList.get(t).getBalance() - money - money * 0.02 < 0)
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money - money * 0.02 - (money - accountList.get(t).getBalance()) * 0.05);
}
else accountList.get(t).setBalance(accountList.get(t).getBalance() - money - money * 0.02);
}
else
{ //透支
if(accountList.get(t).getBalance() >= 0)
{
if(accountList.get(t).getBalance() - money - money * 0.02 - (money - accountList.get(t).getBalance()) * 0.05 < -50000)
{
System.out.println("Sorry,your account balance is insufficient.");
m = 1;
}
else
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money - money * 0.02 - (money - accountList.get(t).getBalance()) * 0.05);
}
}
else
{
if(accountList.get(t).getBalance() - money - money * 0.02 - (money * 0.05) < -50000)
{
System.out.println("Sorry,your account balance is insufficient.");
m = 1;
}
else
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money - money * 0.02 - (money * 0.05));
}
}
}
}
else //存款
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money);
}
}
if(name.compareTo("中国工商银行") == 0)
{
if(money >= 0) //取款
{
if(money <= accountList.get(t).getBalance())
{ //未透支
if(accountList.get(t).getBalance() - money - money * 0.03 < 0)
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money - money * 0.03 - (money - accountList.get(t).getBalance()) * 0.05);
}
else accountList.get(t).setBalance(accountList.get(t).getBalance() - money - money * 0.03);
}
else
{ //透支
if(accountList.get(t).getBalance() >= 0)
if(accountList.get(t).getBalance() - money - money * 0.03 - (money - accountList.get(t).getBalance()) * 0.05 < -50000)
{
System.out.println("Sorry,your account balance is insufficient.");
m = 1;
}
else
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money - money * 0.03 - (money - accountList.get(t).getBalance()) * 0.05);
}
else
{
if(accountList.get(t).getBalance() - money - money * 0.03 - (money * 0.05) < -50000)
{
System.out.println("Sorry,your account balance is insufficient.");
m = 1;
}
else
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money - money * 0.03 - (money * 0.05));
}
}
}
}
else //存款
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money);
}
}
if(name.compareTo("中国农业银行") == 0)
{
if(money >= 0) //取款
{
if(money <= accountList.get(t).getBalance())
{ //未透支
if(accountList.get(t).getBalance() - money - money * 0.04 < 0)
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money - money * 0.04 - (money - accountList.get(t).getBalance()) * 0.05);
}
else accountList.get(t).setBalance(accountList.get(t).getBalance() - money - money * 0.04);
}
else
{ //透支
if(accountList.get(t).getBalance() >= 0)
if(accountList.get(t).getBalance() - money - money * 0.04 - (money - accountList.get(t).getBalance()) * 0.05 < -50000)
{
System.out.println("Sorry,your account balance is insufficient.");
m = 1;
}
else
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money - money * 0.04 - (money - accountList.get(t).getBalance()) * 0.05);
}
else
{
if(accountList.get(t).getBalance() - money - money * 0.04 - (money * 0.05) < -50000)
{
System.out.println("Sorry,your account balance is insufficient.");
m = 1;
}
else
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money - money * 0.04 - (money * 0.05));
}
}
}
}
else //存款
{
accountList.get(t).setBalance(accountList.get(t).getBalance() - money);
}
}
}
}
}
public void show()
{
if(m == 0)
{
if(money >= 0) //取款
{
System.out.println("业务:取款" + " " + accountList.get(t).getName() + "在" + name + "的" + number + "号ATM机上取款¥" + df.format(money));
if(accountList.get(t).getBalance() == 0) System.out.println("当前余额为¥0.00");
else System.out.println("当前余额为¥" + df.format(accountList.get(t).getBalance()));
}
else
{
money = -money;
System.out.println("业务:取款" + " " + accountList.get(t).getName() + "在" + name + "的" + number + "号ATM机上存款¥" + df.format(money));
System.out.println("当前余额为¥" + df.format(accountList.get(t).getBalance()));
}
}
}
}
public class Main
{
public static void main(String[] args)
{
ArrayList < String > ATMList1 = new ArrayList < String > ();
ATMList1.add("01");
ATMList1.add("02");
ATMList1.add("03");
ATMList1.add("04");
Bank bankjian = new Bank("中国建设银行", ATMList1);
ArrayList < String > ATMList2 = new ArrayList < String > ();
ATMList2.add("05");
ATMList2.add("06");
Bank bankgong = new Bank("中国工商银行", ATMList2);
ArrayList < String > ATMList3 = new ArrayList < String > ();
ATMList3.add("07");
ATMList3.add("08");
ATMList3.add("09");
ATMList3.add("10");
ATMList3.add("11");
Bank banknong = new Bank("中国农业银行", ATMList3);
ArrayList < Bank > bankList = new ArrayList < Bank > ();
bankList.add(bankjian);
bankList.add(bankgong);
bankList.add(banknong);
ArrayList < String > cardList1 = new ArrayList < String > ();
cardList1.add("6217000010041315709");
cardList1.add("6217000010041315715");
Account account1 = new Account("杨过", bankList, bankjian, "3217000010041315709", "借记账号", "88888888", 10000.00, cardList1);
ArrayList < String > cardList2 = new ArrayList < String > ();
cardList2.add("6217000010041315718");
Account account2 = new Account("杨过", bankList, bankjian, "3217000010041315715", "借记账号", "88888888", 10000.00, cardList2);
ArrayList < String > cardList3 = new ArrayList < String > ();
cardList3.add("6217000010051320007");
Account account3 = new Account("郭靖", bankList, bankjian, "3217000010051320007", "借记账号", "88888888", 10000.00, cardList3);
ArrayList < String > cardList4 = new ArrayList < String > ();
cardList4.add("6222081502001312389");
Account account4 = new Account("张无忌", bankList, bankgong, "3222081502001312389", "借记账号", "88888888", 10000.00, cardList4);
ArrayList < String > cardList5 = new ArrayList < String > ();
cardList5.add("6222081502001312390");
Account account5 = new Account("张无忌", bankList, bankgong, "3222081502001312390", "借记账号", "88888888", 10000.00, cardList5);
ArrayList < String > cardList6 = new ArrayList < String > ();
cardList6.add("6222081502001312399");
cardList6.add("6222081502001312400");
Account account6 = new Account("张无忌", bankList, bankgong, "3222081502001312399", "借记账号", "88888888", 10000.00, cardList6);
ArrayList < String > cardList7 = new ArrayList < String > ();
cardList7.add("6222081502051320785");
Account account7 = new Account("韦小宝", bankList, bankgong, "3222081502051320785", "借记账号", "88888888", 10000.00, cardList7);
ArrayList < String > cardList8 = new ArrayList < String > ();
cardList8.add("6222081502051320786");
Account account8 = new Account("韦小宝", bankList, bankgong, "3222081502051320786", "借记账号", "88888888", 10000.00, cardList8);
ArrayList < String > cardList9 = new ArrayList < String > ();
cardList9.add("6640000010045442002");
cardList9.add("6640000010045442003");
Account account9 = new Account("张三丰", bankList, bankjian, "3640000010045442002", "贷记账号", "88888888", 10000.00, cardList9);
ArrayList < String > cardList10 = new ArrayList < String > ();
cardList10.add("6640000010045441009");
Account account10 = new Account("令狐冲", bankList, bankgong, "3640000010045441009", "贷记账号", "88888888", 10000.00, cardList10);
ArrayList < String > cardList11 = new ArrayList < String > ();
cardList11.add("6630000010033431001");
Account account11 = new Account("乔峰", bankList, banknong, "3630000010033431001", "贷记账号", "88888888", 10000.00, cardList11);
ArrayList < String > cardList12 = new ArrayList < String > ();
cardList12.add("6630000010033431008");
Account account12 = new Account("洪七公", bankList, banknong, "3630000010033431008", "贷记账号", "88888888", 10000.00, cardList12);
ArrayList < Account > accountList = new ArrayList < Account > ();
accountList.add(account1);
accountList.add(account2);
accountList.add(account3);
accountList.add(account4);
accountList.add(account5);
accountList.add(account6);
accountList.add(account7);
accountList.add(account8);
accountList.add(account9);
accountList.add(account10);
accountList.add(account11);
accountList.add(account12);
Scanner in = new Scanner(System.in);
//卡号 密码 ATM 机编号 金额
String abc = " ";
Check1 check1 = null;
Check2 check2 = null;
abc = in .nextLine();
while(abc.compareTo("#") != 0)
{
String[] shuju = abc.split(" ");
ArrayList < String > list = new ArrayList < String > ();
for(int i = 0; i < shuju.length; i++)
{
if(shuju[i].compareTo("") == 0)
{
for(int j = i; j < shuju.length - 1; j++)
{
shuju[j] = shuju[j + 1];
}
}
}
for(int i = 0; i < shuju.length; i++)
{
if(shuju[i].compareTo("") == 0) break;
else list.add(shuju[i]);
}
if(list.size() != 1)
{
//System.out.println("ok");
double money = Double.valueOf(shuju[3]);
check1 = new Check1(accountList, list.get(0), list.get(1), list.get(2), money);
if(check1.check())
{
Access access = new Access(accountList, bankList, list.get(0), list.get(1), list.get(2), money);
access.access();
access.show();
}
}
else if(list.size() == 1)
{
check2 = new Check2(accountList, list.get(0));
if(check2.check())
{
Show show = new Show(accountList, list.get(0));
show.show();
}
}
abc = in .nextLine();
}
}
}

class DateUtil {
private int year;
private int month;
private int day;

public DateUtil(int year, int month, int day) {
    this.year = year;
    this.month = month;
    this.day = day;
}

public DateUtil(){}

public void setYear(int year) {
    this.year = year;
}

public void setMonth(int month) {
    this.month = month;
}

public void setDay(int day) {
    this.day = day;
}

public int getYear() {
    return year;
}

public int getMonth() {
    return month;
}

public int getDay() {
    return day;
}

}`

posted @ 2021-06-20 23:51  无始道长  阅读(100)  评论(0)    收藏  举报