NCHUWXW第三次大作业总结
NCHUWXW第三次大作业总结
第三个博客了O(∩_∩)O哈哈~
目录
1. 前言. 总结三次题目集的知识点、题量、难度等情况
2. 设计与分析:对题目的提交源码进行分析
3. 采坑心得:对源码的提交过程中出现的问题及心得进行总结
4. 改进建议:对相应题目的编码改进给出自己的见解
5. 总结:对本阶段三次题目集的综合性总结
一. 前言
   1. 这一次主要是重点学会类的设计,设计设计设计,要设计好这些东西还是比较难的,我觉得先想好这些类图怎么设计,在开始干,例如这个类里面写啥,然后那些类里写啥,然后在合在一起,这样设计就会很好,题目集很少,但是太烧了,知识点也很少,主要是麻烦,脑袋要炸了。
2. 现在来讲一讲这些题目集的题目的重点了。
3.不知不觉间JAVA的学习已经接近尾声。在最近几周的学习中大伙主要学习的都是javafx相关的知识以及运用办法,在最后部分穿插了些许软件建模的相关知识。在最后三次的题集中我们主要对java中较为重要的部分进行了相关的训练,包括类的继承、多态性使用方法、接口的应用以及类结构设设计。此次题集训练的题量较少,但由于考察知识点的数量众多以及需要我们自行对类结构进行设计,因此具有一定的难度。但另一方面也为我们进行知识点的查缺补漏提供了一途径,对今后相关知识的学习以及运用具有较大帮助。
题目集7
(1)老生长谈的问题了,只需要把上次那个加一点排序就好了,排序依旧是上次那个树map,我主要是那个只有搞了很久,有点麻烦,你们就自己想想吧。
(2)第二个就是分组问题了,这个题它不难只需要加一点就好了,非常easy
题目集8,9
(1)8和9一起讲吧,这个就是银行的问题,主要想好那些类的设计怎么设计?那些类里面该设计什么,而且还要设计好,在下次作业那里改一下就好,主要是存取款超了,就要立马终止它,不能让它一直下去,否则查看的话,会出现超的情况,这次仅仅只有一题但是有一点考察数据处理能力(偏正则表达式方面,属于自己的弱项),所以难度偏中上。,ATM机系统,运用java面向对象思维,建立多个类,每个类处理一件事,特别之处就是取款和存款之处需要加以区别,题目并无太多新颖特殊之处。在题目集8的基础之上,遵循开闭原则,再创建一个信用卡账户类,从而实现借贷功能,除此之外,再到withdraw()方法处理跨行转账是增加流程。
二. 设计与分析
1.面向对象程序设计-2021-物联网-7
       7-1 图形卡片排序游戏 (40 分)
       7-2 图形卡片分组游戏 (60 分)
输入格式:
- 首先,在一行上输入一串数字(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)就是对前面的那些题的加了排序,还是非常简单的,两个题就不讲了,没有什么好讲的,不会的话就可以remake了,好吧实际上可以看看我上面那个讲解,加个排序就好了这边直接加代码了
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Scanner; import java.util.TreeSet; abstract class Shape { private String shapeName; public abstract double getArea(); public abstract boolean validate(); public Shape() { } public Shape(String shapeName) { this.shapeName = shapeName; } public void setShapeName(String shapeName) { this.shapeName=shapeName; } public String getShapeName() { return shapeName; } public String toString() { return getShapeName()+":"+String.format("%.2f ",getArea()); } } class Card implements Comparable<Card> { 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; } public int compareTo(Card card) { return -(int)(shape.getArea()-card.getShape().getArea()); } } class Circle extends Shape { private double r; public boolean validate() { if(this.r>0) { return true; } else { return false; } } public Circle() { } public Circle(double r) { this.r = r; } public double getr() { return r; } public void setr() { this.r=r; } public double getArea() { return Math.PI*r*r; } } class Rectangle extends Shape { private double length,width; public Rectangle() { } public boolean validate() { if(this.width>0&this.length>0) { return true; } else { return false; } } public double getWidth() { return width; } public void setWidth(double width) { this.width = width; } public double getHeight() { return length; } public void setHeight(double length) { this.length = length; } public Rectangle(double length, double width) { this.length = length; this.width = width; } public double getArea() { return width*length; } } class Triangle extends Shape { private double side1,side2,side3; public Triangle() { } public Triangle(double side1,double side2,double side3) { this.side1 = side1; this.side2 = side2; this.side3 = side3; } public double getArea() { return Math.sqrt((side1+side2+side3)*(side1+side2-side3)*(side1+side3-side2)*(side2+side3-side1))/4; } public boolean validate() { double a[] = new double[3]; a[0] = this.side1; a[1] = this.side2; a[2] = this.side3; Arrays.sort(a); if (!(side1>0&&side2>0&&side3>0)) return false; if (a[0] + a[1] > a[2]) { return true; } else { return false; } } } class Trapezoid extends Shape{ private double w,l,h; //创建无参构造方法 public Trapezoid() { } //创建带参构造方法 public Trapezoid(double w, double l, double h) { this.w = w; this.l = l; this.h = h; } //getter public double C(){ return w; } public double B(){ return l; } public double H(){ return h; } //setter public void setC(double w){ this.w=w; } public void setB(double l){ this.l=l; } public void setH(double h){ this.h=h; } public double getArea() { // TODO 自动生成的方法存根 return (w+l)*h/2; } public boolean validate() { // TODO 自动生成的方法存根 return l>0&&w>0&&h>0; } } public class Main { public static Scanner scan = new Scanner(System.in); public static void main(String[] args) { // TODO 自动生成的方法存根 int num; ArrayList<Integer> list = new ArrayList<Integer>(); num=scan.nextInt(); while(num != 0) { if(num < 0 || num > 4) { System.out.println("Wrong Format"); System.exit(0); } list.add(num); num = scan.nextInt(); } DealCardList dealCardList = new DealCardList(list); if(!dealCardList.validate()) { System.out.println("Wrong Format"); System.exit(0); } dealCardList.showResult(); scan.close(); } int id; double balance; double tax; double withdraw; double deposit; public int getid(int id) { return id; } public void setid() { this.id=id; } public double getbalance(double balance) { return balance; } public void setbalance() { this.balance=balance; } public double gettax(double tax) { return tax; } } class DealCardList { ArrayList<Card> cardList=new ArrayList<>(); public DealCardList() { } public DealCardList(ArrayList<Integer> list) { for (Integer integer : list) { if (integer==0)break; switch (integer) { case 1: Card card1=new Card(new Circle(Main.scan.nextDouble())); card1.getShape().setShapeName("Circle"); cardList.add(card1); break; case 2: Card card2=new Card(new Rectangle(Main.scan.nextDouble(),Main.scan.nextDouble())); card2.getShape().setShapeName("Rectangle"); cardList.add(card2); break; case 3: Card card3=new Card(new Triangle(Main.scan.nextDouble(),Main.scan.nextDouble(),Main.scan.nextDouble())); card3.getShape().setShapeName("Triangle"); cardList.add(card3); break; case 4: Card card4=new Card(new Trapezoid(Main.scan.nextDouble(),Main.scan.nextDouble(),Main.scan.nextDouble())); card4.getShape().setShapeName("Trapezoid"); cardList.add(card4); break; } } } public boolean validate() { boolean flag=true; for (Card a:cardList) { if (!a.getShape().validate()) { flag=false; break; } } return flag; } public void cardSort() { TreeSet<Card> cards = new TreeSet<>(cardList); for (Card card : cards) { System.out.print(card.getShape()); } } public double getAllArea() { double sum=0; for (Card card:cardList) { sum+=card.getShape().getArea(); } return sum; } public void showResult() { 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",getAllArea()); } }
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Scanner; import java.util.TreeSet; abstract class Shape { private String shapeName; public abstract double getArea(); public abstract boolean validate(); public Shape() { } public Shape(String shapeName) { this.shapeName = shapeName; } public void setShapeName(String shapeName) { this.shapeName=shapeName; } public String getShapeName() { return shapeName; } public String toString() { return getShapeName()+":"+String.format("%.2f ",getArea()); } } class Card implements Comparable<Card> { 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; } public int compareTo(Card card) { return -(int)(shape.getArea()-card.getShape().getArea()); } } class Circle extends Shape { private double r; public boolean validate() { if(this.r>0) { return true; } else { return false; } } public Circle() { } public Circle(double r) { this.r = r; } public double getr() { return r; } public void setr() { this.r=r; } public double getArea() { return Math.PI*r*r; } } class Rectangle extends Shape { private double length,width; public Rectangle() { } public boolean validate() { if(this.width>0&this.length>0) { return true; } else { return false; } } public double getWidth() { return width; } public void setWidth(double width) { this.width = width; } public double getHeight() { return length; } public void setHeight(double length) { this.length = length; } public Rectangle(double length, double width) { this.length = length; this.width = width; } public double getArea() { return width*length; } } class Triangle extends Shape { private double side1,side2,side3; public Triangle() { } public Triangle(double side1,double side2,double side3) { this.side1 = side1; this.side2 = side2; this.side3 = side3; } public double getArea() { return Math.sqrt((side1+side2+side3)*(side1+side2-side3)*(side1+side3-side2)*(side2+side3-side1))/4; } public boolean validate() { double a[] = new double[3]; a[0] = this.side1; a[1] = this.side2; a[2] = this.side3; Arrays.sort(a); if (!(side1>0&&side2>0&&side3>0)) return false; if (a[0] + a[1] > a[2]) { return true; } else { return false; } } } class Trapezoid extends Shape{ private double w,l,h; //创建无参构造方法 public Trapezoid() { } //创建带参构造方法 public Trapezoid(double w, double l, double h) { this.w = w; this.l = l; this.h = h; } //getter public double C(){ return w; } public double B(){ return l; } public double H(){ return h; } //setter public void setC(double w){ this.w=w; } public void setB(double l){ this.l=l; } public void setH(double h){ this.h=h; } public double getArea() { // TODO 自动生成的方法存根 return (w+l)*h/2; } public boolean validate() { // TODO 自动生成的方法存根 return l>0&&w>0&&h>0; } } public class Main { public static Scanner scan = new Scanner(System.in); public static void main(String[] args) { // TODO 自动生成的方法存根 int num; ArrayList<Integer> list = new ArrayList<Integer>(); num=scan.nextInt(); if (num==0){ System.out.println("Wrong Format"); System.exit(0); } while(num != 0) { if(num < 0 || num > 4) { System.out.println("Wrong Format"); System.exit(0); } list.add(num); num = scan.nextInt(); } DealCardList dealCardList = new DealCardList(list); if(!dealCardList.validate()) { System.out.println("Wrong Format"); System.exit(0); } dealCardList.showResult(); scan.close(); } int id; double balance; double tax; double withdraw; double deposit; public int getid(int id) { return id; } public void setid() { this.id=id; } public double getbalance(double balance) { return balance; } public void setbalance() { this.balance=balance; } public double gettax(double tax) { return tax; } } class DealCardList { ArrayList<Card> cardList=new ArrayList<>(); double[] zs=new double[4]; public DealCardList() { } public DealCardList(ArrayList<Integer> list) { for (Integer integer : list) { if (integer==0)break; switch (integer) { case 1: Card card1=new Card(new Circle(Main.scan.nextDouble())); card1.getShape().setShapeName("Circle"); cardList.add(card1); break; case 2: Card card2=new Card(new Rectangle(Main.scan.nextDouble(),Main.scan.nextDouble())); card2.getShape().setShapeName("Rectangle"); cardList.add(card2); break; case 3: Card card3=new Card(new Triangle(Main.scan.nextDouble(),Main.scan.nextDouble(),Main.scan.nextDouble())); card3.getShape().setShapeName("Triangle"); cardList.add(card3); break; case 4: Card card4=new Card(new Trapezoid(Main.scan.nextDouble(),Main.scan.nextDouble(),Main.scan.nextDouble())); card4.getShape().setShapeName("Trapezoid"); cardList.add(card4); break; } } } public boolean validate() { boolean flag=true; for (Card a:cardList) { if (!a.getShape().validate()) { flag=false; break; } } return flag; } public void yuan(){ zs[0]=0; System.out.print("["); for (Card a:cardList){ if(a.getShape().getShapeName().equals("Circle")){ System.out.print(a.getShape()); zs[0]=zs[0]+a.getShape().getArea(); } } System.out.print("]"); } //输出矩形的数据并计算总面积 public void juxing(){ zs[1]=0; System.out.print("["); for (Card a:cardList){ if(a.getShape().getShapeName().equals("Rectangle")){ System.out.print(a.getShape()); zs[1]=zs[1]+a.getShape().getArea(); } } System.out.print("]"); } //输出三角形的数据并计算总面积 public void sanjiaoxing(){ zs[2]=0; System.out.print("["); for (Card a:cardList){ if(a.getShape().getShapeName().equals("Triangle")){ System.out.print(a.getShape()); zs[2]=zs[2]+a.getShape().getArea(); } } System.out.print("]"); } //输出梯形的数据并计算总面积 public void tixing(){ zs[3]=0; System.out.print("["); for (Card a:cardList){ if(a.getShape().getShapeName().equals("Trapezoid")){ System.out.print(a.getShape()); zs[3]=zs[3]+a.getShape().getArea(); } } System.out.print("]"); } //从大到小输出圆的数据 public void ypx(){ TreeSet<Card> kp = new TreeSet<>(cardList); System.out.print("["); for (Card a:kp){ if(a.getShape().getShapeName().equals("Circle")){ System.out.print(a.getShape()); } } System.out.print("]"); } //从大到小输出矩形的数据 public void jxpx(){ TreeSet<Card> kp = new TreeSet<>(cardList); System.out.print("["); for (Card a:kp){ if(a.getShape().getShapeName().equals("Rectangle")){ System.out.print(a.getShape()); } } System.out.print("]"); } //从大到小输出三角形的数据 public void sjxpx(){ TreeSet<Card> kp = new TreeSet<>(cardList); System.out.print("["); for (Card a:kp){ if(a.getShape().getShapeName().equals("Triangle")){ System.out.print(a.getShape()); } } System.out.print("]"); } //从大到小输出梯形的数据 public void txpx(){ TreeSet<Card> kp = new TreeSet<>(cardList); System.out.print("["); for (Card a:kp){ if(a.getShape().getShapeName().equals("Trapezoid")){ System.out.print(a.getShape()); } } System.out.print("]"); } //找出最大总面积 public double getMax(){ double max=0; int i; for (i=0;i<4;i++){ if(max<zs[i]){ max=zs[i]; } } return max; } public void showResult() { System.out.println("The original list:"); System.out.print("["); for (Card card : cardList) { System.out.print(card.getShape()); } System.out.print("]"); System.out.println("\nThe Separated List:"); yuan();juxing();sanjiaoxing();tixing(); System.out.println("\nThe Separated sorted List:"); ypx();jxpx();sjxpx();txpx(); System.out.printf("\nThe max area:%.2f\n",getMax()); } }

此次代码设计一个突出的要求便是使用多态继承进行相应的实现以使程序的结构避免过于繁琐。因此我们创建一个list将输入的图像类型进行保存。后续对列中的数据进行提出并进行相应参数的输入。我们创建一个类来进行list的处理,根据所存list的相应内容创建出相应的对象包括Circle,Triangle,Rectangle,Trapezoid。同时创建的该四个类同时继承抽象类Shape。
2.面向对象程序设计-2021-物联网-8-9
这两个题目集就放在一起来讲了,重点讲9把,9会了8应该也就会了好吧,其实是我把9在8的基础上改的那个代码没了,哈哈。
设计ATM仿真系统,具体要求参见作业说明。 OO作业9-1题目说明.pdf 输入格式: 每一行输入一次业务操作,可以输入多行,最终以字符#终止。具体每种业务操作输入格式如下: 取款功能输入数据格式: 卡号 密码 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编号]上取款¥[金额] 当前余额为¥[金额] 其中,[]说明括起来的部分为输出属性或变量,金额均保留两位小数。 ③查询余额业务输出 业务:查询余额 ¥[金额] 金额保留两位小数。

由题意得该题是在上题的基础上增加了新的要求,即存在部分用户可进行金额预支同时各个用户都可以进行跨行取款,但设置了透支额度以及各个银行跨行存取的费用。该题的大体思路与上题基本一致,除了在ArrayList中添入新的成员之外,为了区分可透支的用户以及不可进行透支的用户,除了建立一个新的类用于判断外,我们可以采用更加简便的方法,即在people类中根据各个客户的属性设置为一个0-1变量。在后续的计算判断中,通过对该变量进行相关的检测达到事半功倍的目的。
此题中较为繁琐之处我认为是进行余额不足的判定,此处我们既要对无法进行透支的用户与可进行透支的用户进行相应的区分,同时也要对已达到透支的用户加以辨别并给出相应的返回结果。此处代码如下所示:
import java.util.Scanner; import java.util.ArrayList; class Bank { String bankname; ArrayList<String> ATMList; ArrayList<Account> account; ArrayList<ATM> atm; public Bank(String bankname,ArrayList<String> ATMList){ this.bankname=bankname; this.ATMList=ATMList; } } class Account { private String name; private String account; private String password; private double balance; ArrayList<Bank> banklist; Bank bank; private ArrayList<String> cardList; private ArrayList<String> ATMList; public Account(String name,String account,String password,double balance,ArrayList<Bank> banklist,Bank bank,ArrayList<String> cardList,ArrayList<String> ATMList) { this.name=name;this.account=account;this.password=password;this.balance=balance;this.bank=bank;this.banklist=banklist;this.cardList=cardList;this.ATMList=ATMList; } 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 void setBalance(double balance) { this.balance = balance; } } class Check { String name;String password; ArrayList<Account> account=new ArrayList(); double money;String number;String card; ArrayList<String> CardList=new ArrayList(); public Check(ArrayList<Account> account,String card,String password,String number,double money) { this.account=account; this.card=card; this.password=password; this.number=number; this.money=money; } public boolean checkaccount() { boolean flag=false; int z=0; for (int i=0;i<account.size();i++) {for(int j=0;j<account.get(i).getCardList().size();j++) {if(card.equals(account.get(i).getCardList().get(j))==true){flag=true;z=i;break;} } if(flag==true) break; } return flag; } public boolean checkpassword() { boolean flag=true; if(flag==true) { if(password.equals("88888888")==true) return true; else { return false; } } return flag; } public boolean checkATM() { boolean flag=false; int z=0; for(int i=0;i<account.get(z).banklist.size();i++) { for(int j=0;j<account.get(z).banklist.get(i).ATMList.size();j++) { if(number.equals(account.get(z).banklist.get(i).ATMList.get(j))==true) { flag=true; z=i; break; } } if(flag==true) break; } if(flag==false) { return false; } return flag; } public boolean checkPass() { boolean flag=false; boolean flag1=false; int z=0; for (int i=0;i<account.size();i++) { for(int j=0;j<account.get(i).getCardList().size();j++) { if(card.equals(account.get(i).getCardList().get(j))==true) { flag=true; z=i; break; } } if(flag==true) break; } if(flag==true) { for(int i=0;i<account.get(z).bank.ATMList.size();i++) { if(number.equals(account.get(z).bank.ATMList.get(i))) { flag1=true; break; } } } return flag1; } } class ATM { String name;String password;double money;String number;String card; ArrayList<Account> account=new ArrayList();ArrayList<String> CardList=new ArrayList();ArrayList<Account> accountList=new ArrayList(); public ATM(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 boolean didaccess() { int i,j; int t=0; for(i=0;i<account.size();i++){ for(j=0;j<account.get(i).getCardList().size();j++){ if(CardList.equals(account.get(i).getCardList().get(j))){ t=i; break; } } } if((money>accountList.get(t).getBalance())||((accountList.get(t).getBalance()-money)<(-50000))) return false; else {return true;} } } class Check1 { ArrayList<Account> accountList; String card; public Check1(ArrayList<Account> accountList, String card){ this.accountList = accountList; this.card = card; } public boolean check(){ int i,j; int flag=0; for(i=0;i<accountList.size();i++){ for(j=0;j<accountList.get(i).getCardList().size();j++){ if (card.equals(accountList.get(i).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; } } } class Check2 { ArrayList<Account> accountList; String card;String password; String number;double money; public Check2(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 i,j,k=0; int flag=0; for(i=0;i<accountList.size();i++){ for(j=0;j<accountList.get(i).getCardList().size();j++){ if (card.equals(accountList.get(i).getCardList().get(j))){ k=i; break; } } } for(i=0;i<accountList.get(k).bank.ATMList.size();i++){ if(number.equals(accountList.get(k).bank.ATMList.get(i))){ flag=1; break; } } if(flag==1){ return false; } else { return true; } } } class Check3 { ArrayList<Account> accountList;ArrayList<Account> accountList1;String card;String password;String number;double money; public Check3(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 i,j,k=0,flag=0; for(i=0;i<accountList1.size();i++){for(j=0;j<accountList1.get(i).getCardList().size();j++){if(card.equals(accountList1.get(i).getCardList().get(j))){flag=1;break;}}} if(flag==1){return true; } else { return false; } } } class Show{ ArrayList<Account> accountList;String card;String password;String number;double money;String bankname; 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 i,j,t=0; for(i=0;i<accountList.size();i++){for(j=0;j<accountList.get(i).getCardList().size();j++){if(card.equals(accountList.get(i).getCardList().get(j))){t=i;break;}}} if(number.equals("01")||number.equals("02")||number.equals("03")||number.equals("04")) bankname="中国建设银行"; else if(number.equals("05")||number.equals("06")) bankname="中国工商银行"; else if(number.equals("07")||number.equals("08")||number.equals("09")||number.equals("10")||number.equals("11")) bankname="中国农业银行"; if(money>0){ if(accountList.get(t).getBalance()>=(-50000)){System.out.printf("业务:取款 "+accountList.get(t).getName()+"在"+bankname+"的"+number+"号ATM机上取款¥%.2f\n",money);System.out.printf("当前余额为¥%.2f\n",accountList.get(t).getBalance());} else {System.out.println("Sorry,your account balance is insufficient.");} } else{money=-money;System.out.printf("业务:存款 "+accountList.get(t).getName()+"在"+bankname+"的"+number+"号ATM机上存款¥%.2f\n",money);System.out.printf("当前余额为¥%.2f\n",accountList.get(t).getBalance());} } } public class Main { public static void main(String[] args) { ArrayList<String> ATMList1 = new ArrayList<>();ATMList1.add("01"); ATMList1.add("02");ATMList1.add("03");ATMList1.add("04");Bank jsyh = new Bank("中国建设银行", ATMList1); ArrayList<String> ATMList2 = new ArrayList<>();ATMList2.add("05");ATMList2.add("06");Bank gsyh = new Bank("中国工商银行", ATMList2); ArrayList<String> ATMList3 = new ArrayList<>();ATMList3.add("07");ATMList3.add("08");ATMList3.add("09");ATMList3.add("10");ATMList3.add("11");Bank nyyh = new Bank("中国农业银行", ATMList3); ArrayList<String> ATMList = new ArrayList<>();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<Bank> bankList = new ArrayList<>();bankList.add(jsyh);bankList.add(gsyh);bankList.add(nyyh); ArrayList<String> cardList1 = new ArrayList<>(); cardList1.add("6217000010041315709");cardList1.add("6217000010041315715"); Account account1 = new Account("杨过", "3217000010041315709", "88888888", 10000.00, bankList, jsyh,cardList1,ATMList); ArrayList<String> cardList2 = new ArrayList<>(); cardList2.add("6217000010041315718"); Account account2 = new Account("杨过", "3217000010041315715", "88888888", 10000.00, bankList,jsyh,cardList2,ATMList); ArrayList<String> cardList3 = new ArrayList<>(); cardList3.add("6217000010051320007"); Account account3 = new Account("郭靖", "3217000010051320007", "88888888", 10000.00, bankList,jsyh,cardList3,ATMList); ArrayList<String> cardList4 = new ArrayList<>(); cardList4.add("6222081502001312389"); Account account4 = new Account("张无忌", "3222081502001312389", "88888888", 10000.00, bankList,gsyh,cardList4,ATMList); ArrayList<String> cardList5 = new ArrayList<>(); cardList5.add("6222081502001312390"); Account account5 = new Account("张无忌", "3222081502001312390", "88888888", 10000.00, bankList,gsyh,cardList5,ATMList); ArrayList<String> cardList6 = new ArrayList<>(); cardList6.add("6222081502001312399");cardList6.add("6222081502001312400"); Account account6 = new Account("张无忌", "3222081502001312399", "88888888", 10000.00, bankList,gsyh,cardList6,ATMList); ArrayList<String> cardList7 = new ArrayList<>(); cardList7.add("6222081502051320785"); Account account7 = new Account("韦小宝", "3222081502051320785", "88888888", 10000.00, bankList,gsyh,cardList7,ATMList); ArrayList<String> cardList8 = new ArrayList<>(); cardList8.add("6222081502051320786"); Account account8 = new Account("韦小宝", "3222081502051320786", "88888888", 10000.00, bankList,gsyh,cardList8,ATMList); ArrayList<String> cardList9 = new ArrayList<>(); cardList9.add("6640000010045442002");cardList9.add("6640000010045442003"); Account account9 = new Account("张三丰", "3640000010045442002", "88888888", 10000.00, bankList,jsyh,cardList9,ATMList); ArrayList<String> cardList10 = new ArrayList<>(); cardList10.add("6640000010045441009"); Account account10 = new Account("令狐冲", "3640000010045441009", "88888888", 10000.00, bankList,gsyh,cardList10,ATMList); ArrayList<String> cardList11 = new ArrayList<>(); cardList11.add("6630000010033431001"); Account account11 = new Account("乔峰", "3630000010033431001", "88888888", 10000.00, bankList,nyyh,cardList11,ATMList); ArrayList<String> cardList12 = new ArrayList<>(); cardList12.add("6630000010033431008"); Account account12 = new Account("洪七公", "3630000010033431008", "88888888", 10000.00, bankList,nyyh,cardList12,ATMList); ArrayList<Account> accountList = new ArrayList<>(); 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); ArrayList<Account> accountList1=new ArrayList<>(); accountList1.add(account9);accountList1.add(account10); accountList1.add(account11);accountList1.add(account12); Scanner input=new Scanner(System.in);String kp; Check check;Check1 check1; Check2 check2;Check3 check3; ATM atmaccount; ATM atmaccount1; ATM atmaccount2;ATM atmaccount3; kp=input.nextLine(); while(!kp.equals("#")) { int i,j,t=0; String[] shuju=kp.split("\\s+"); for(i=0;i<accountList.size();i++) {for(j=0;j<accountList.get(i).getCardList().size();j++){if(shuju[0].equals(accountList.get(i).getCardList().get(j))){t=i;break;}}} if(shuju.length==1) { check1 = new Check1(accountList,shuju[0]); if(check1.check()==false) {break;} else { if(accountList.get(t).getBalance()<-50000) break; else{System.out.printf("业务:查询余额 ¥%.2f",accountList.get(t).getBalance());} } } else if(shuju.length==4) { check = new Check(accountList,shuju[0],shuju[1],shuju[2],Double.parseDouble(shuju[3])); check2 = new Check2(accountList,shuju[0],shuju[1],shuju[2],Double.parseDouble(shuju[3])); check3 = new Check3(accountList,accountList1,shuju[0],shuju[1],shuju[2],Double.parseDouble(shuju[3])); if(check.checkaccount()==true) { if(check.checkpassword()==true) { if(check.checkATM()==true) { if(check3.check()==false) { if(check2.check()) { atmaccount1= new ATM(accountList,shuju[0],shuju[1],shuju[2],Double.parseDouble(shuju[3])); if(atmaccount1.didaccess()==true) { double q=0; for(i=0;i<accountList.size();i++) { for(j=0;j<accountList.get(i).getCardList().size();j++) { if(shuju[0].equals(accountList.get(i).getCardList().get(j))) { t=i; break; } } } for(i=0;i<accountList.get(t).getATMList().size();i++) { if(shuju[2].equals(accountList.get(t).getATMList().get(0))||shuju[2].equals(accountList.get(t).getATMList().get(1))||shuju[2].equals(accountList.get(t).getATMList().get(2))||shuju[2].equals(accountList.get(t).getATMList().get(3))){ q=Double.parseDouble(shuju[3])*0.02; break; } else if (shuju[2].equals(accountList.get(t).getATMList().get(4))||shuju[2].equals(accountList.get(t).getATMList().get(5))){ q=Double.parseDouble(shuju[3])*0.03; break; } else if(shuju[2].equals(accountList.get(t).getATMList().get(6))||shuju[2].equals(accountList.get(t).getATMList().get(7))||shuju[2].equals(accountList.get(t).getATMList().get(8))||shuju[2].equals(accountList.get(t).getATMList().get(9))||shuju[2].equals(accountList.get(t).getATMList().get(10))){ q=Double.parseDouble(shuju[3])*0.04; break; } } accountList.get(t).setBalance(accountList.get(t).getBalance()-q-Double.parseDouble(shuju[3])); if(accountList.get(t).getBalance()<0) {System.out.println("Sorry,your account balance is insufficient.");break;} else {Show show = new Show(accountList,shuju[0], shuju[1],shuju[2],Double.parseDouble(shuju[3]));show.show();} } else { System.out.println("Sorry,your account balance is insufficient."); break; } } else { atmaccount= new ATM(accountList,shuju[0],shuju[1],shuju[2],Double.parseDouble(shuju[3])); if(atmaccount.didaccess()==true) { for(i=0;i<accountList.size();i++) { for(j=0;j<accountList.get(i).getCardList().size();j++) { if(shuju[0].equals(accountList.get(i).getCardList().get(j))) { t=i; break; } } } accountList.get(t).setBalance(accountList.get(t).getBalance()-Double.parseDouble(shuju[3]));Show show = new Show(accountList,shuju[0], shuju[1],shuju[2],Double.parseDouble(shuju[3]));show.show(); } else {System.out.println("Sorry,your account balance is insufficient.");break;} } } else { if(check2.check()) { atmaccount3= new ATM(accountList,shuju[0],shuju[1],shuju[2],Double.parseDouble(shuju[3])); int k=0;double l,q=0; for (i = 0; i < accountList.size(); i++) { for (j = 0; j < accountList.get(i).getCardList().size(); j++) {if (shuju[0].equals(accountList.get(i).getCardList().get(j))) {k = i;break;} } } for (i = 0; i < accountList.get(k).getATMList().size(); i++) { if (shuju[2].equals(accountList.get(k).getATMList().get(0)) || shuju[2].equals(accountList.get(k).getATMList().get(1)) || shuju[2].equals(accountList.get(k).getATMList().get(2)) || shuju[2].equals(accountList.get(k).getATMList().get(3))) {q = Double.parseDouble(shuju[3]) * 0.02; break;} else if (shuju[2].equals(accountList.get(k).getATMList().get(4)) || shuju[2].equals(accountList.get(k).getATMList().get(5))) {q = Double.parseDouble(shuju[3]) * 0.03; break;} else if (shuju[2].equals(accountList.get(k).getATMList().get(6)) || shuju[2].equals(accountList.get(k).getATMList().get(7)) || shuju[2].equals(accountList.get(k).getATMList().get(8)) || shuju[2].equals(accountList.get(k).getATMList().get(9)) || shuju[2].equals(accountList.get(k).getATMList().get(10))) {q = Double.parseDouble(shuju[3]) * 0.04; break; } } if (accountList.get(k).getBalance() >=Double.parseDouble(shuju[3])&&accountList.get(k).getBalance()>0) { accountList.get(k).setBalance(accountList.get(k).getBalance() - Double.parseDouble(shuju[3]) - q); } else if(accountList.get(k).getBalance() <Double.parseDouble(shuju[3])&&accountList.get(k).getBalance()>0){ l = (Double.parseDouble(shuju[3]) - accountList.get(k).getBalance()) * 0.05; accountList.get(k).setBalance(accountList.get(k).getBalance() - Double.parseDouble(shuju[3]) - l - q); } else if(accountList.get(k).getBalance() <Double.parseDouble(shuju[3])&&accountList.get(k).getBalance()<=0){ l=Double.parseDouble(shuju[3])*0.05;accountList.get(k).setBalance(accountList.get(k).getBalance() - Double.parseDouble(shuju[3]) - l - q); } {Show show = new Show(accountList,shuju[0], shuju[1],shuju[2],Double.parseDouble(shuju[3]));show.show();} } else { atmaccount2= new ATM(accountList,shuju[0],shuju[1],shuju[2],Double.parseDouble(shuju[3]));double l; for(i=0;i<accountList.size();i++) { for(j=0;j<accountList.get(i).getCardList().size();j++) {if(shuju[0].equals(accountList.get(i).getCardList().get(j))){t=i;break; }} } if(accountList.get(t).getBalance()>Double.parseDouble(shuju[3])&&accountList.get(t).getBalance()>0) { accountList.get(t).setBalance(accountList.get(t).getBalance()-Double.parseDouble(shuju[3])); } else if(accountList.get(t).getBalance()<Double.parseDouble(shuju[3])&&accountList.get(t).getBalance()>0) { l=(Double.parseDouble(shuju[3])-accountList.get(t).getBalance())*0.05;accountList.get(t).setBalance(accountList.get(t).getBalance()-Double.parseDouble(shuju[3])-l); } else if(accountList.get(t).getBalance()<Double.parseDouble(shuju[3])&&accountList.get(t).getBalance()<=0) { l=Double.parseDouble(shuju[3])*0.05; accountList.get(t).setBalance(accountList.get(t).getBalance()-Double.parseDouble(shuju[3])-l); } Show show = new Show(accountList,shuju[0], shuju[1],shuju[2],Double.parseDouble(shuju[3]));show.show(); } } } else{System.out.println("Sorry,the ATM's id is wrong."); break;} } else{System.out.println("Sorry,your password is wrong.");break;} } else{System.out.println("Sorry,this card does not exist."); break;} } kp=input.nextLine(); } } }
三、踩坑心得
1.此次在进行ATM类设计的第二问的求解时,在对于余额不足的判定以及跨行取款的费用计算是需要去进行一番斟酌的,若一借记用户进行跨行取款时,其账户扣除的费用为手续费+取出金额,若其存款金额小于以上费用则进行相应的报错。对于借贷用户在是否超出预支限额的判定时,同样需要进行上述的计算并加上相应的预支手续费。其中较为令人迷惑的是,若一借贷用户账号有2000元并进行3000元的存款操作,他需要缴纳3000*手续费+1000*借贷利率而不是2000*手续费+1000借贷利率,由于此问题导致了求解过程阻滞了较长时间。该部分的具体代码如下:
 View Code2.接下来便是该题的多次取款最后透支的检查项,最初自认为借贷用户在进行透支取款时无需进行相应的手续费缴纳,仅需缴纳5%的相应利率,最后通过多次输入样例进行测试最后成功进行了修改。
3.在进行图形分组时需要对各组的数据进行相应的排序并取出最大的面积值。此处需要修改Comparable接口,但在进行修改之后输出结果始终会出现部分的错误,最后采用了相关数值调用冒泡排序完成该问题的解决。
设计思路:首先对题目有一个大致的了解,联系生活中银行的工作情况,银行有银行卡。银行又有客户,客户又有姓名,性别的属性,银行又有银行卡,银行卡有银行卡好和密码,还有余额,余额又有利率,通过这些实际关系来构造类,并进行操作。
四、改进建议
1.老生重谈的问题,对于if-else结构过多导致的圈复杂度过高的问题,无非就是三目运算符,提前return,switch-case,表驱动法等优化方案,或者创建相应的类执行i并简化f-else的任务实现功能,最后则是改变自己的思路,探究有无更加优秀的算法或是解法了。
五、总结
1.通过这三次的PTA题集训练,首先无疑是对这一个学期中的所学知识进行了一定的回顾以及使用,同时对于相关的内容以及知识点进行了充分的回顾以及掌握。通过类设计问题体会到一个合理程序框架的构建对于程序以及编写者的影响之大,在今后的学习以及代码学习之中,我们都应保持良好的编程习惯,,在编程之前进行相关问题解决方法的合理设计,做到"三思而后行",使我们的工作质量大大提高并达到事半功倍的效果。
2.对于继承、多态、接口,封装等多种编程设计思路以及技术运用,由于使用的次数较少且理解程度并未到达完全透彻的境界.因此我们还需要对其加强学习并多多进行训练,提高自身的综合水平.
3.从目前的情况来看,老师的教学方法是较为成功且对学生的有益的:在学习完Java的基本知识以及设计方法后穿插JavaFX的知识将理论与实践进行结合,最后讲述软件建模相关的知识使我们拥有更加优秀的设计思维以及相应的问题解决方案,在课堂上进行相应代码的编写修改,无疑加深了学生对于相关知识的理解。布置的作业现在看来也是逐渐由浅入深,一步步的锻炼我们的编码能力,所取得的效果还是可圈可点的。
4.通过利用不同的题目对自己所掌握的知识进行考察,我发现自己仍存在对于部分知识点理解不够透彻以及不能灵活运用等问题,这就需要自觉进行查缺补漏了,相信随着时间推移自己能够取得相应的进步,在充分理解的基础上并能够灵活使用Java这门语言。
期末了就水了主要是过了太久了有点忘了,题目集有点少,写不了太多了,而且题目就是升级的,不好讲,跟着我思路来写有点麻烦。可以去看看我同学的

                
            
        
浙公网安备 33010602011771号