题目集7~9的总结性Blog

(1)前言:总结三次题目集的知识点、题量、难度等情况

7-1主要考察了类的继承,多态性的使用方法及接口的应用。难度:中等。

7-2主要考察掌握类的继承、多态性使用方法以及接口的应用。难度:中等。

题量:适中。

8-1主要考察对java综合能力的考察。难度:中等偏上。

题量:适中。

9-1主要考察对java综合能力的考察。难度:偏难。

题量:适中。

(2)设计与分析:

  ①题目集7(7-1)、(7-2)两道题目的递进式设计分析总结

题目集7(7-1)

源码:

import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
//在Main类中定义一个静态Scanner对象,这样在其它类中如果想要使用该对象进行输入,则直接
//使用Main.input.next…即可(避免采坑)
public static Scanner input = new Scanner(System.in);
public static void main(String[] args){
ArrayList<Integer> list = new ArrayList<Integer>();
int num = input.nextInt();
while(num != 0){
if(num < 0 || num > 4){
System.out.println("Wrong Format");
System.exit(0);
}
list.add(num);
num = input.nextInt();
}
DealCardList dealCardList = new DealCardList(list);
if(!dealCardList.validate()){
System.out.println("Wrong Format");
System.exit(0);
}
dealCardList.showResult();
input.close();
}
}

class DealCardList{
ArrayList<Card> cardList=new ArrayList<>();

public DealCardList() {
}

public DealCardList(ArrayList<Integer> card) {
for (Integer integer : card) {
if (integer==0)break;
switch (integer){
case 1:
Card card1=new Card(new Circle(Main.input.nextDouble()));
card1.getShape().setShapeName("Circle");
cardList.add(card1);
break;
case 2:
Card card2=new Card(new Rectangle(Main.input.nextDouble(),Main.input.nextDouble()));
card2.getShape().setShapeName("Rectangle");
cardList.add(card2);
break;
case 3:
Card card3=new Card(new Triangle(Main.input.nextDouble(),Main.input.nextDouble(),Main.input.nextDouble()));
card3.getShape().setShapeName("Triangle");
cardList.add(card3);
break;
case 4:
Card card4=new Card(new Trapezoid(Main.input.nextDouble(),Main.input.nextDouble(),Main.input.nextDouble()));
card4.getShape().setShapeName("Trapezoid");
cardList.add(card4);
break;
}

}
}
public boolean validate(){
boolean ret=true;
for (Card card : cardList) {
if (!card.getShape().validate()){
ret=false;
break;
}
}
return ret;
}
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());
}
}
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;
}

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

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 abstract double getArea();
public abstract boolean validate();

/**
* 重写了toString的方法
* 利用Shape类的shapeName变量来表示相应的图形,
* 而不是用getclass方法得到类名
* @return
*/
@Override
public String toString() {
return getShapeName()+":"+String.format("%.2f ",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 this.radius>0;
}
}

class Rectangle extends Shape{
private double width,height;

public Rectangle() {
}

public Rectangle(double width, double height) {
this.width = width;
this.height = height;
}

public double getWidth() {
return width;
}

public void setWidth(double width) {
this.width = width;
}

public double getHeight() {
return height;
}

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

@Override
public double getArea() {
return height*width;
}

@Override
public boolean validate() {
return width>0&&height>0;
}
}

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

@Override
public double getArea() {
double p=(side1+side2+side3)/2;
return Math.sqrt(p*(p-side1)*(p-side2)*(p-side3));
}

@Override
public boolean validate() {
boolean ret=true;
if (!(side1>0&&side3>0&&side2>0))ret=false;
else{
if (!(side1+side2>side3&&side1+side3>side2&&side2+side3>side1))ret=false;
}
return ret;
}
}

class Trapezoid extends Shape{
private double topSide,bottomSide,height;

public Trapezoid() {
}

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

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

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

设计:主要是要把相关的类给设计出来还有需掌握好接口的应用。

题目集7(7-2)

源码:


import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.TreeSet;

//Chulishuju类
class Chulishuju{
ArrayList<Card> cardList=new ArrayList<>();
double[] zs=new double[4];

public Chulishuju(ArrayList<Integer> c){
for (Integer a:c){
if (a==0){
break;
}
else {
switch (a) {
case 1 :
Card a1 = new Card(new Circle(Main.x.nextDouble()));
cardList.add(a1);
a1.getShape().setName("Circle");
break;
case 2 :
Card b1 = new Card(new Rectangle(Main.x.nextDouble(), Main.x.nextDouble()));
cardList.add(b1);
b1.getShape().setName("Rectangle");
break;
case 3 :
Card c1 = new Card(new Triangle(Main.x.nextDouble(), Main.x.nextDouble(), Main.x.nextDouble()));
cardList.add(c1);
c1.getShape().setName("Triangle");
break;
case 4 :
Card d1 = new Card(new Trapezoid(Main.x.nextDouble(), Main.x.nextDouble(), Main.x.nextDouble()));
cardList.add(d1);
d1.getShape().setName("Trapezoid");
break;
}
}
}
}
//判断数据是否合法
public boolean pdsfhf(){
boolean kp=true;
for (Card a:cardList){
if (!a.getShape().pdsfhf()){
kp=false;
break;
}
}
return kp;
}
//输出圆的数据并计算总面积
public void yuan(){
zs[0]=0;
System.out.print("[");
for (Card a:cardList){
if(a.getShape().getName().equals("Circle")){
System.out.print(a.getShape());
zs[0]=zs[0]+a.getShape().Mj();
}
}
System.out.print("]");
}
//输出矩形的数据并计算总面积
public void juxing(){
zs[1]=0;
System.out.print("[");
for (Card a:cardList){
if(a.getShape().getName().equals("Rectangle")){
System.out.print(a.getShape());
zs[1]=zs[1]+a.getShape().Mj();
}
}
System.out.print("]");
}
//输出三角形的数据并计算总面积
public void sanjiaoxing(){
zs[2]=0;
System.out.print("[");
for (Card a:cardList){
if(a.getShape().getName().equals("Triangle")){
System.out.print(a.getShape());
zs[2]=zs[2]+a.getShape().Mj();
}
}
System.out.print("]");
}
//输出梯形的数据并计算总面积
public void tixing(){
zs[3]=0;
System.out.print("[");
for (Card a:cardList){
if(a.getShape().getName().equals("Trapezoid")){
System.out.print(a.getShape());
zs[3]=zs[3]+a.getShape().Mj();
}
}
System.out.print("]");
}
//从大到小输出圆的数据
public void ypx(){
TreeSet<Card> kp = new TreeSet<>(cardList);
System.out.print("[");
for (Card a:kp){
if(a.getShape().getName().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().getName().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().getName().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().getName().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 show(){//输出
System.out.println("The original list:");
System.out.print("[");
for (Card a : cardList) {
System.out.print(a.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());
}
}
//Card类
class Card implements Comparable<Card>{
private Shape shape;
//创建无参构造方法
public Card() {
}
//创建带参构造方法
public Card(Shape shape) {
this.shape = shape;
}
//getter
public Shape getShape() {
return shape;
}
//setter
public void setShape(Shape shape) {
this.shape = shape;
}
public int compareTo(Card card) {
return -(int)(shape.Mj()-card.getShape().Mj());
}
}
//Shape类
abstract class Shape {
private String name;
//创建无参构造方法
public Shape() {
}
//创建带参构造方法
public Shape(String name) {
this.name = name;
}
//getter
public String getName() {
return name;
}
//setter
public void setName(String name) {
this.name = name;
}
//面积
public abstract double Mj();
//判断数据是否合法
public abstract boolean pdsfhf();

public String toString() {
return getName()+":"+String.format("%.2f ",Mj());
}
}
//Circle类
class Circle extends Shape{
private double r;
//创建无参构造方法
public Circle(){
}
//创建带参构造方法
public Circle(double r){
this.r=r;
}
//getter
public double getR(){
return r;
}
//setter
public void setR(double r){
this.r = r;
}
//判断数据是否合法
public boolean pdsfhf() {
return r>0;
}
//计算圆面积
public double Mj(){
double mj=Math.PI*r*r;
return mj;
}
}
//Rectangle类
class Rectangle extends Shape{
private double a,b;
//创建无参构造方法
public Rectangle(){
}
//创建带参构造方法
public Rectangle(double a, double b){
this.a=a;
this.b=b;
}
//getter
public double A(){
return a;
}
public double B(){
return b;
}
//setter
public void setA(double a){
this.a=a;
}
public void setB(double b){
this.b=b;
}
//判断数据是否合法
public boolean pdsfhf() {
return a>0&&b>0;
}
//计算矩形面积
public double Mj(){
return a*b;
}
}
//Triangle类
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;
}
//getter
public double A(){
return a;
}
public double B(){
return b;
}
public double C(){
return c;
}
//setter
public void setA(double a){
this.a=a;
}
public void setB(double b){
this.b=b;
}
public void setC(double c){
this.c=c;
}
//判断数据是否合法
public boolean pdsfhf(){
Double[] bc=new Double[3];
bc[0]=a;bc[1]=b;bc[2]=c;
boolean z=true;
Arrays.sort(bc);
if(a<=0&&b<=0&&c<=0){
z=false;
}
else{
if(!(a+b>c)){
z=false;
}
}
return z;
}
//计算三角形面积
public double Mj(){
double s1,s2;
s1=(a+b+c)/2;
s2=Math.sqrt(s1*(s1-a)*(s1-b)*(s1-c));
return s2;
}
}
//Trapezoid类
class Trapezoid extends Shape{
private double c,b,h;
//创建无参构造方法
public Trapezoid() {
}
//创建带参构造方法
public Trapezoid(double c, double b, double h) {
this.c = c;
this.b = b;
this.h = h;
}
//getter
public double C(){
return c;
}
public double B(){
return b;
}
public double H(){
return h;
}
//setter
public void setC(double a){
this.c=c;
}
public void setB(double b){
this.b=b;
}
public void setH(double c){
this.h=h;
}
//判断数据是否合法
public boolean pdsfhf() {
return b>0&&c>0&&h>0;
}
//计算梯形面积
public double Mj() {
return (c+b)*h/2;
}
}

//主类
public class Main{
public static Scanner x = new Scanner(System.in);//在Main类中定义一个静态Scanner对象,这样在其它类中如果想要使用该对象进行输入,则直接使用Main.input.next...即可(避免采坑)
public static void main(String[] args){
ArrayList<Integer> xzlist = new ArrayList<>();
int xz;
xz=x.nextInt();
if (xz==0){
System.out.println("Wrong Format");
System.exit(0);
}
while (xz!=0){//循环输入第一行数据
if(xz>4||xz<0){//如果输入的数据不合法
System.out.println("Wrong Format");
System.exit(0);
}
xzlist.add(xz);
xz=x.nextInt();
}
//检查数据是否合法
Chulishuju chulishuju=new Chulishuju(xzlist);
if(!chulishuju.pdsfhf()){
System.out.println("Wrong Format");
System.exit(0);
}

chulishuju.show();
x.close();
}
}

设计:主要是要把相关的类给设计出来还有需掌握好接口的应用。(在此基础上,增加了图形分类的功能)

    ②题目集8和题目集9两道ATM机仿真题目的设计思路分析总结

附源码:

//代码长度为31kb!!!

import java.util.Scanner;
import java.util.ArrayList;

//Bank类
class Bank{
String bankname;
ArrayList<String> ATMList;
//创建无参构造方法
public Bank(){
}
//创建带参构造方法
public Bank(String bankname,ArrayList<String> ATMList)
{
this.bankname=bankname;
this.ATMList=ATMList;
}
//getter
public String getBankname() {
return bankname;
}
public ArrayList<String> getATMList() {
return ATMList;
}
//setter
public void setBankname(String bankname){
this.bankname=bankname;
}
public void setATMList(ArrayList<String> tATMList){
this.ATMList=ATMList;
}
}
//Account类
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;
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.account=account;
this.password=password;
this.balance=balance;
this.bank=bank;
this.banklist=banklist;
this.cardList=cardList;
this.ATMList=ATMList;
this.BanknameList=BanknameList;
}
//getter
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 ArrayList<String> getATMList() {
return ATMList;
}
public ArrayList<String> getBanknameList() {
return BanknameList;
}
//setter
public void setName(String name) {
this.name = name;
}
public void setAccount(String account) {
this.account = account;
}
public void setPassword(String password) {
this.password = password;
}
public void setBalance(double balance) {
this.balance = balance;
}
public void setCardList(ArrayList<String> cardList) {
this.cardList = cardList;
}
public void setATMList(ArrayList<String> ATMList) {
this.ATMList = ATMList;
}
public void setBanknameList(ArrayList<String> BanknameList) {
this.BanknameList = BanknameList;
}
}

//存取款的检查类
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 i,j,k=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;
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;
}
//检查ATM机编号是否正确
if(flag==2){
for(i=0;i<accountList.get(k).banklist.size();i++){
for(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;

}
}
}
//余额查询的检查类
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;
int 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 Check4{
ArrayList<Account> accountList;
String card;
String password;
String number;
double money;

public Check4(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;
}
}
}
//检查是否跨行
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 i,j,k=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;
//System.out.println(accountList.get(k));
break;
}
}
}
accountList.get(k).setBalance(accountList.get(k).getBalance()-money);
}
}
//借记账号跨行存取款类
class Access1{
ArrayList<Account> accountList;
String card;
String password;
String number;
double money;
public Access1(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 i,j,k=0;
double q=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).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);
}
}
//贷记账号未跨行存取款类
class Access2{
ArrayList<Account> accountList;
String card;
String password;
String number;
double money;
public Access2(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 i,j,k=0;
double l;
//卡号校验
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;
//System.out.println(accountList.get(k));
break;
}
}
}
//System.out.println("wkh");
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);
}
}
}
//贷记账号跨行存取款类
class Access3 {
ArrayList<Account> accountList;
String card;
String password;
String number;
double money;

public Access3(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 i, j, k = 0;
double l,q=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;
//System.out.println(accountList.get(k));
break;
}
}
}
//跨行取款手续费
for (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;
}
}
//System.out.println("kh");
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 void show(){
int i,j,k=0;
String bankname="";
//卡号校验
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).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);
System.out.printf("当前余额为¥%.2f\n",accountList.get(k).getBalance());
}
else {
System.out.println("Sorry,your account balance is insufficient.");//输入取款金额大于账户余额
}
}
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 Show1{
ArrayList<Account> accountList;
String card;
public Show1(ArrayList<Account> accountList,String card){
this.accountList=accountList;
this.card=card;
}
public void show1(){
int i,j;
int 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;
}
}
}
System.out.printf("业务:查询余额 ¥%.2f\n",accountList.get(t).getBalance());
}
}
//贷记账号存取款的展示类
class Show2{
ArrayList<Account> accountList;
ArrayList<Account> accountList1;
String card;
String password;
String number;
double money;

public Show2(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 void show() {
int i, j, k = 0;
String bankname = "";
//卡号校验
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).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);
System.out.printf("当前余额为¥%.2f\n",accountList.get(k).getBalance());
}
else {
System.out.println("Sorry,your account balance is insufficient.");//透支金额超过规定最大透支金额
}
}
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 class Main {
public static void main(String[] args) {
//ATM机编号数组
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> banknameList = new ArrayList<>();
banknameList.add("中国建设银行");
banknameList.add("中国工商银行");
banknameList.add("中国农业银行");

//用户数组
ArrayList<String> cardList1 = new ArrayList<>();
cardList1.add("6217000010041315709");
cardList1.add("6217000010041315715");
Account account1 = new Account("杨过", "3217000010041315709", "88888888", 10000.00, bankList, jsyh,cardList1,ATMList,banknameList);

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

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

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

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

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

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

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

ArrayList<String> cardList9 = new ArrayList<>();
cardList9.add("6640000010045442002");
cardList9.add("6640000010045442003");
Account account9 = new Account("张三丰", "3640000010045442002", "88888888", 10000.00, bankList,jsyh,cardList9,ATMList,banknameList);

ArrayList<String> cardList10 = new ArrayList<>();
cardList10.add("6640000010045441009");
Account account10 = new Account("令狐冲", "3640000010045441009", "88888888", 10000.00, bankList,gsyh,cardList10,ATMList,banknameList);

ArrayList<String> cardList11 = new ArrayList<>();
cardList11.add("6630000010033431001");
Account account11 = new Account("乔峰", "3630000010033431001", "88888888", 10000.00, bankList,nyyh,cardList11,ATMList,banknameList);

ArrayList<String> cardList12 = new ArrayList<>();
cardList12.add("6630000010033431008");
Account account12 = new Account("洪七公", "3630000010033431008", "88888888", 10000.00, bankList,nyyh,cardList12,ATMList,banknameList);

//借记账号用户总数组
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 x=new Scanner(System.in);

String kp;
Check check;
Check1 check1;
Check2 check2;
Check3 check3;
Check4 check4;

kp=x.nextLine();
while(!kp.equals("#")){
String[] shuju=kp.split("\\s+");//输入的每行数据用空格隔开,存为数组
/*
for(i=0;i<shuju.length;i++) {
System.out.println(shuju[i]);
}
*/

if(shuju.length!=1){//存取款
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]));
check4 = new Check4(accountList,shuju[0],shuju[1],shuju[2],Double.parseDouble(shuju[3]));

if (check.check()){
if(check3.check()){//贷记账号
//System.out.println("贷记账号");
if(check2.check()){//跨行
Access3 access3 = new Access3(accountList,shuju[0], shuju[1],shuju[2],Double.parseDouble(shuju[3]));
access3.access();
//System.out.println("跨行");
Show2 show2 = new Show2(accountList,accountList1,shuju[0], shuju[1],shuju[2],Double.parseDouble(shuju[3]));
show2.show();
}
else {//未跨行
Access2 access2 = new Access2(accountList,shuju[0], shuju[1],shuju[2],Double.parseDouble(shuju[3]));
access2.access();
//System.out.println("未跨行");
Show2 show2 = new Show2(accountList,accountList1,shuju[0], shuju[1],shuju[2],Double.parseDouble(shuju[3]));
show2.show();
}
}
else {//借记账号
if(check4.check()){//金额检查
if(check2.check()){//跨行
Access1 access1 = new Access1(accountList,shuju[0], shuju[1],shuju[2],Double.parseDouble(shuju[3]));
access1.access();
Show show = new Show(accountList,accountList1,shuju[0], shuju[1],shuju[2],Double.parseDouble(shuju[3]));
show.show();
}
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 Check1(accountList,shuju[0]);
if(check1.check()){
Show1 show1= new Show1(accountList,shuju[0]);
show1.show1();
}
}
kp=x.nextLine();
}
}

 

 

总结:

关键是要把实验的个个功能给分离开来,逐步实现后再把各个功能汇总进行产生相应的联系。

(3)采坑心得:对源码的提交过程中出现的问题及心得进行总结,务必做到详实,拿数据、源码及测试结果说话,切忌假大空

对应不会写的题目,我们我不要着急。不要就不写了。应该有迎难而上的精神,而不应该就放弃,不去做 !

(4)改进建议:对相应题目的编码改进给出自己的见解,做到可持续改进

改进建议:代码中纯在许多累赘的地方。需要化简。而不要弄得很麻烦!

(5)总结:对本阶段三次题目集的综合性总结,学到了什么,哪些地方需要进一步学习及研究,对教师、课程、作业、实验、课上及课下组织方式等方面的改进建议及意见。

通过这三次作业的学习:

我学会了类的合理使用。继承的使用。Comparable接口的使用。

哪些地方值得改进:

不会写很大的作业。只能勉勉强强的应付相关的小作业。应该多花时间在java这门课程上。为以后的作业打好相关的基础!!!

 

 

posted @ 2021-06-15 17:00  爱吃辣条的光头  阅读(57)  评论(0)    收藏  举报