前言:
通过前一个月的基础学习,对Java有了一定的了解,在这一个月中学习的知识难度明显增加,题目集的难度也随之增加。第四次的题目集主要考察对LinkedHashSet、ArrayList、Java的封装性、LocalDate类、String类、Integer类、Scanner类等的了解和简单使用。第五次的题目集主要考察对正则表达式的理解和使用,以及对类与类之间聚合关系的建立和应用。第六次题目集则考察对继承、多态的理解和使用,以及对类的初步设计。相对而言,第4、5次题目集的难度较接近,而第6次题目集的难度增加较显著。
设计,分析与心得:
第四次的题目集主要考察对LinkedHashSet、ArrayList、Java的封装性、LocalDate类、String类、Integer类、Scanner类等的了解和简单使用。考察的内容较多,但主要难点在于7-1的菜单计价程序。
由于没有合理规划好时间,未在规定时间内完成7-1题目。借总结的机会再仔细理解一下题目意思和要求。
输入内容包括桌号、时间、序号、菜品名称、份额、分数、增删菜品;程序需要完成计算并输出总价格(包含规定时间内打折情况)。
根据题目要求,设计了Dish(菜品)、Record(记录)、Menu(菜单)、Order(点单)、Table(餐桌)五个类。类与类之间的关系主要是关联。
第五次题目集考察聚合关系的应用,以7-5、7-6为例。
7-5的类图如下所示(题目已给出):
题目要求:程序需要实现1、求下n天 2、求前n天 3、求两个日期相差的天数,三个要求。结合题目要求和类图可知,题目需要将Year的对象设置成Month的属性,将Month的对象设置为Day的属性,将Day的对象设置为DateUtil的属性,应用类与类的聚合关系来实现题目需求。
7-6的题目要求和7-5相近,同样是实现1、求下n天 2、求前n天 3、求两个日期相差的天数,这三个要求,不同点在于两道题目所采用的聚合的方式不同。7-5采用是的一层一层的聚合方式,而7-6直接上Year、Month、Day三个类的对象直接设置为DateUtil的属性,我认为两者相较,7-6的聚合方式在代码的书写上更加简洁明了,表达更加清楚,而7-5的代码在书写过程中有些冗长,比如在DateUtil类中需要获取year的值时,需要day.getMonth().getYear().getValue(),而7-6只需要year.getValue()。但7-5式的聚合更能反应出Year、Month、Day三个类之间的关联。 7-6的类图如下所示(题目已给出):
在各个类方法的具体书写中,因为有第三次题目集7-4的基础,所以没有遇到太大的问题,需要注意的两个点在于Int的范围。在第一次写完提交后,发现整型数最大值测试和整数类型的最小值测试,两个测试点错误,所以将计算方法改为逐天增加或减少至所给的天数为0来求得前N天和后N天的日期。在计算两个两个日期间隔N天时,采用的是先通过equalTowDates(date)判断日期是否相等,再通过compareDates(date)判断日期的前后,然后再逐天累加计算相隔的天数。和第三次题目集7-4不同的在于这次的日期包含了先后的情况,而不是单一的前面输入的日期在前,后面输入的日期在后。
7-5代码如下:
import java.util.Scanner; class DateUtil { private Day day; //无参构造方法 public DateUtil() { } //带参构造方法 public DateUtil(Day day) { this.day = day; } //getter public Day getDay() { return day; } //setter public void setDay(Day day) { this.day = day; } //检查日期是否合法 public boolean checkInputValidity(){ if(day.validate()){ return true; } else { return false; } } //比较日期前后 public boolean compareDates(DateUtil date){ if(day.getMonth().getYear().getValue() < date.day.getMonth().getYear().getValue()) { return true; }else if(day.getMonth().getYear().getValue() == date.day.getMonth().getYear().getValue() && day.getMonth().getValue() < date.day.getMonth().getValue() ) { return true; }else if(day.getMonth().getYear().getValue() == date.day.getMonth().getYear().getValue() && day.getMonth().getValue() == date.day.getMonth().getValue() && day.getValue() <= date.day.getValue()) { return true; }else { return false; } } //比较日期是否相等 public boolean equalTowDates(DateUtil date){ if(day.getMonth().getYear().getValue() == date.day.getMonth().getYear().getValue() && day.getMonth().getValue() == date.day.getMonth().getValue() && day.getValue() == date.day.getValue()){ return true; } else { return false; } } //显示日期 public String showDate(){ return day.getMonth().getYear().getValue()+"-"+day.getMonth().getValue()+"-"+day.getValue(); } //计算n天后 public DateUtil getNextNDays(int n) { for (int i = 0; i < n; i++) { if(day.getMonth().getYear().isLeapYear()) { day.setMon_maxnum(29); } else { day.setMon_maxnum(28); } day.dayIncrement(); day.resetMin(); day.getMonth().resetMin(); } DateUtil date1 = new DateUtil(day); return date1; } //计算n天前 public DateUtil getPreviousNDays(int n) { for (int i = 0; i < n; i++) { if(day.getMonth().getYear().isLeapYear()) { day.setMon_maxnum(29); } else { day.setMon_maxnum(28); } day.dayReduction(); day.resetMax(); day.getMonth().resetMax(); } DateUtil date2 = new DateUtil(day); return date2; } //计算日期相差天数 public int getDaysofDates(DateUtil date) { int n = 0; while(!equalTowDates(date)){ if(compareDates(date)){ if(day.getMonth().getYear().isLeapYear()) { day.setMon_maxnum(29); } else { day.setMon_maxnum(28); } day.dayIncrement(); day.resetMin(); day.getMonth().resetMin(); n++; } else { if(day.getMonth().getYear().isLeapYear()) { day.setMon_maxnum(29); } else { day.setMon_maxnum(28); } day.dayReduction(); day.resetMax(); day.getMonth().resetMax(); n++; } } return n; } } class Year { private int value; //无参构造方法 public Year() { } //带参构造方法 public Year(int value) { this.value = value; } //getter public int getValue() { return value; } //setter public void setValue(int value) { this.value = value; } //判断是否为闰年 public boolean isLeapYear(){ if(value % 4 == 0 && value % 100 != 0 || value % 400 == 0) { return true; } else { return false; } } //校验数据是否合法 public boolean validate(){ if(value > 2050 || value < 1900){ return false; } else { return true; } } //年份加一 public void yearIncrement(){ value ++; } //年份减一 public void yearReduction(){ value --; } } class Month { private int value; private Year year; //无参构造方法 public Month() { } //带参构造方法 public Month(int value, Year year) { this.value = value; this.year = year; } //getter public int getValue() { return value; } //setter public void setValue(int value) { this.value = value; } //getter public Year getYear() { return year; } //setter public void setYear(Year year) { this.year = year; } //月份复位为1 public void resetMin(){ if(value > 12 ){ value = 1; year.yearIncrement(); } } //月份设置为12 public void resetMax(){ if(value < 1){ value = 12; year.yearReduction(); } } //校验数据合法性 public boolean validate(){ if((value <= 12 && value >= 1) && year.validate()){ return true; } else { return false; } } //月份增加 public void monthIncrement(){ value ++; } //月份减少 public void monthReduction(){ value --; } } class Day { private int value; private Month month; private int[] mon_maxnum = {31,31,28,31,30,31,30,31,31,30,31,30,31,0}; //带参构造方法 public Day(int value, Month month) { this.value = value; this.month = month; } //无参构造方法 public Day() { } //getter public int getValue() { return value; } //setter public void setValue(int value) { this.value = value; } //getter public Month getMonth() { return month; } //setter public void setMonth(Month month) { this.month = month; } //getter public int[] getMon_maxnum() { return mon_maxnum; } //改变2月份的天数 public void setMon_maxnum(int n) { this.mon_maxnum[2] = n; } //天数复原为1 public void resetMin(){ if(value > mon_maxnum[month.getValue()] ){ value = 1; month.monthIncrement(); } } //天数变为前个月最大天数 public void resetMax(){ if(value < 1 ){ value = mon_maxnum[month.getValue()-1]; month.monthReduction(); } } //校验数据合法性 public boolean validate(){ if(value <= mon_maxnum[month.getValue()] && value >= 1 && month.validate()){ return true; } else { return false; } } //天数增加 public void dayIncrement(){ value ++; } //天数减少 public void dayReduction(){ value --; } } public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int year = 0; int month = 0; int day = 0; int choice = input.nextInt(); if (choice == 1) { // test getNextNDays method int m = 0; year = Integer.parseInt(input.next()); month = Integer.parseInt(input.next()); day = Integer.parseInt(input.next()); Year year1 = new Year(year); Month month1 = new Month(month,year1); Day day1 = new Day(day,month1); DateUtil date = new DateUtil(day1); if (!date.checkInputValidity()) { System.out.println("Wrong Format"); System.exit(0); } m = input.nextInt(); if (m < 0) { System.out.println("Wrong Format"); System.exit(0); } System.out.println(date.getNextNDays(m).showDate()); } else if (choice == 2) { // test getPreviousNDays method int n = 0; year = Integer.parseInt(input.next()); month = Integer.parseInt(input.next()); day = Integer.parseInt(input.next()); Year year1 = new Year(year); Month month1 = new Month(month,year1); Day day1 = new Day(day,month1); DateUtil date = new DateUtil(day1); if (!date.checkInputValidity()) { System.out.println("Wrong Format"); System.exit(0); } n = input.nextInt(); if (n < 0) { System.out.println("Wrong Format"); System.exit(0); } System.out.println(date.getPreviousNDays(n).showDate()); } else if (choice == 3) { //test getDaysofDates method year = Integer.parseInt(input.next()); month = Integer.parseInt(input.next()); day = Integer.parseInt(input.next()); int anotherYear = Integer.parseInt(input.next()); int anotherMonth = Integer.parseInt(input.next()); int anotherDay = Integer.parseInt(input.next()); Year year1 = new Year(year); Month month1 = new Month(month,year1); Day day1 = new Day(day,month1); DateUtil fromDate = new DateUtil(day1); Year year2 = new Year(anotherYear); Month month2 = new Month(anotherMonth,year2); Day day2 = new Day(anotherDay,month2); DateUtil toDate = new DateUtil(day2); if (fromDate.checkInputValidity() && toDate.checkInputValidity()) { System.out.println(fromDate.getDaysofDates(toDate)); } else { System.out.println("Wrong Format"); System.exit(0); } } else{ System.out.println("Wrong Format"); System.exit(0); } } }View Code
7-6代码如下:
import java.util.Scanner; class DateUtil { private Day day; private Month month; private Year year; private int[] mon_maxnum = {31,31,28,31,30,31,30,31,31,30,31,30,31,0}; //无参构造方法 public DateUtil() { } //带参构造方法 public DateUtil(Day day, Month month, Year year) { this.day = day; this.month = month; this.year = year; } public Day getDay() { return day; } public void setDay(Day day) { this.day = day; } public Month getMonth() { return month; } public void setMonth(Month month) { this.month = month; } public Year getYear() { return year; } public void setYear(Year year) { this.year = year; } public void setMon_maxnum(int n) { this.mon_maxnum[2] = n; } //检查日期是否合法 public boolean checkInputValidity(){ //先判断输入的年份是否是闰年,改变2月份的天使 if(year.isLeapYear()) { setMon_maxnum(29); } else { setMon_maxnum(28); } //检查日期 if(month.validate() && year.validate() && day.getValue() <= mon_maxnum[month.getValue()] && day.getValue() >= 1){ return true; } else { return false; } } //比较日期前后 public boolean compareDates(DateUtil date){ if(year.getValue() < date.getYear().getValue()) { return true; }else if(year.getValue() == date.getYear().getValue() && month.getValue() < date.getMonth().getValue() ) { return true; }else if(year.getValue() == date.getYear().getValue() && month.getValue() == date.getMonth().getValue() && day.getValue() <= date.day.getValue()) { return true; }else { return false; } } //判断日期是否相等 public boolean equalTowDates(DateUtil date){ if(year.getValue() == date.getYear().getValue() && month.getValue() == date.getMonth().getValue() && day.getValue() == date.day.getValue()){ return true; } else { return false; } } //显示日期 public String showDate(){ return year.getValue()+"-"+month.getValue()+"-"+day.getValue(); } //后n天 public DateUtil getNextNDays(int n) { for (int i = 0; i < n; i++) { if(year.isLeapYear()) { setMon_maxnum(29); } else { setMon_maxnum(28); } day.dayIncrement(); if(day.getValue() > mon_maxnum[month.getValue()]){ day.setValue(1); month.monthIncrement(); if(month.getValue() > 12){ month.resetMin(); year.yearIncrement(); } } } DateUtil date1 = new DateUtil(day,month,year); return date1; } //前n天 public DateUtil getPreviousNDays(int n) { for (int i = 0; i < n; i++) { if(year.isLeapYear()) { setMon_maxnum(29); } else { setMon_maxnum(28); } day.dayReduction(); if(day.getValue() < 1){ day.setValue(mon_maxnum[month.getValue() - 1]); month.monthReduction(); if(month.getValue() < 1 ){ month.resetMax(); year.yearReduction(); } } } DateUtil date2 = new DateUtil(day,month,year); return date2; } //求两个日前间相差的天数 public int getDaysofDates(DateUtil date) { int n = 0; while(!equalTowDates(date)){ //先判断日期的前后 if(compareDates(date)){ if(year.isLeapYear()) { setMon_maxnum(29); } else { setMon_maxnum(28); } day.dayIncrement(); if(day.getValue() > mon_maxnum[month.getValue()]){ day.setValue(1); month.monthIncrement(); if(month.getValue() > 12){ month.resetMin(); year.yearIncrement(); } } n++; } else { if(year.isLeapYear()) { setMon_maxnum(29); } else { setMon_maxnum(28); } day.dayReduction(); if(day.getValue() < 1){ day.setValue(mon_maxnum[month.getValue() - 1]); month.monthReduction(); if(month.getValue() < 1 ){ month.resetMax(); year.yearReduction(); } } n++; } } return n; } } class Year { private int value; //无参构造方法 public Year() { } //带参构造方法 public Year(int value) { this.value = value; } public int getValue() { return value; } public void setValue(int value) { this.value = value; } //判断是否为闰年 public boolean isLeapYear(){ if(value % 4 == 0 && value % 100 != 0 || value % 400 == 0) { return true; } else { return false; } } //校验数据是否合法 public boolean validate(){ if(value > 2020 || value < 1820){ return false; } else { return true; } } //年份加一 public void yearIncrement(){ value ++; } //年份减一 public void yearReduction(){ value --; } } class Month { private int value; //无参构造方法 public Month() { } //带参构造方法 public Month(int value) { this.value = value; } public int getValue() { return value; } public void setValue(int value) { this.value = value; } //月份复位为1 public void resetMin(){ if(value > 12 ){ value = 1; } } //月份设置为12 public void resetMax(){ if(value < 1){ value = 12; } } //校验数据合法性 public boolean validate(){ if(value <= 12 && value >= 1){ return true; } else { return false; } } //月份加一 public void monthIncrement(){ value ++; } //月份减一 public void monthReduction(){ value --; } } class Day { private int value; //带参构造方法 public Day(int value) { this.value = value; } //无参构造方法 public Day() { } public int getValue() { return value; } public void setValue(int value) { this.value = value; } //天数加一 public void dayIncrement(){ value ++; } //天数减一 public void dayReduction(){ value --; } } public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int year = 0; int month = 0; int day = 0; int choice = input.nextInt(); if (choice == 1) { // test getNextNDays method int m = 0; //输入日期 year = Integer.parseInt(input.next()); month = Integer.parseInt(input.next()); day = Integer.parseInt(input.next()); //构造对面 Year year1 = new Year(year); Month month1 = new Month(month); Day day1 = new Day(day); DateUtil date = new DateUtil(day1,month1,year1); //检查日期是否合法 if (!date.checkInputValidity()) { System.out.println("Wrong Format"); System.exit(0); } m = input.nextInt(); if (m < 0) { System.out.println("Wrong Format"); System.exit(0); } //输出结果 System.out.print(date.getYear().getValue() + "-" + date.getMonth().getValue() + "-" + date.getDay().getValue() + " next " + m + " days is:"); System.out.println(date.getNextNDays(m).showDate()); } else if (choice == 2) { // test getPreviousNDays method int n = 0; //输入日期 year = Integer.parseInt(input.next()); month = Integer.parseInt(input.next()); day = Integer.parseInt(input.next()); //构造对象 Year year1 = new Year(year); Month month1 = new Month(month); Day day1 = new Day(day); DateUtil date = new DateUtil(day1,month1,year1); //检查日期是否合法 if (!date.checkInputValidity()) { System.out.println("Wrong Format"); System.exit(0); } n = input.nextInt(); if (n < 0) { System.out.println("Wrong Format"); System.exit(0); } System.out.print(date.getYear().getValue() + "-" + date.getMonth().getValue() + "-" + date.getDay().getValue() + " previous " + n + " days is:"); System.out.println(date.getPreviousNDays(n).showDate()); } else if (choice == 3) { //test getDaysofDates method //输入起始日期 year = Integer.parseInt(input.next()); month = Integer.parseInt(input.next()); day = Integer.parseInt(input.next()); //输入终止日期 int anotherYear = Integer.parseInt(input.next()); int anotherMonth = Integer.parseInt(input.next()); int anotherDay = Integer.parseInt(input.next()); Year year1 = new Year(year); Month month1 = new Month(month); Day day1 = new Day(day); DateUtil fromDate = new DateUtil(day1,month1,year1); Year year2 = new Year(anotherYear); Month month2 = new Month(anotherMonth); Day day2 = new Day(anotherDay); DateUtil toDate = new DateUtil(day2,month2,year2); //判断数据是否合法即计算相差天数 if (fromDate.checkInputValidity() && toDate.checkInputValidity()) { System.out.println("The days between " + fromDate.showDate() + " and " + toDate.showDate() + " are:" + fromDate.getDaysofDates(toDate)); } else { System.out.println("Wrong Format"); System.exit(0); } } else{ System.out.println("Wrong Format"); System.exit(0); } } }View Code
第六次题目集考察了对类的初步设计,以7-4和7-5为例:
7-4题目要求如文件所示:
93fc7ad6-5e85-445a-a759-5790d0baab28.pdf (ptausercontent.com)
根据题目意思,需要设计中国银联(China UnionPay)、银行(Bank)、银行用户(User)、银行账户(Account)、银行卡(Card)、ATM(Automated Teller Machine)六个实体类。
类图设计如下:
初步观察,银联中有多个银行,每个银行可以有多个用户,每个用户可以有多个账户,每个账户可以有多张银行卡,且要求银联,银行,用户,账户,银行卡均设计为独有的类,因此采用和第五次题目集7-5的相同形式,将类与类之间设置为聚合关系,从中国银联(China UnionPay)到银行卡(Card)。但由于类的数量较多,这种方式使得调用比较繁琐,特别是在对对象进行初始化时代码冗长难理解。
在7-5中增加了一些要求,具体如文件所示:
https://images.ptausercontent.com/60abe58e-09db-49b0-b9dc-219a33d2c073.pdf
类的设计要求基本相同,但在设计过程中转变了一下思路,由于在7-5中的发现初始化过程的冗长,且再次仔细阅读题目后,发现目标的最终落脚处在于银行卡Card,后续的操作均以银行卡卡号匹配正确为准为基础。每张银行卡都有卡号、密码、用户、所属账户、所属银行,因此将聚合的形式从中国银联(China UnionPay)到银行卡(Card)改为从银行卡(Card)到中国银联(China UnionPay)。具体类图如下所示:
题目的难度就主要在对类的设计和对题意的理解上,在跨行取款的计算中几次出现错误。多次试错后理解题意。按照题目要求,透支的那部分金额不管在跨行还是不跨行取款时都需要额外计算透支的手续费,而包括透支金额在内的所有取款金额都要计算跨行取款的手续费,意思为当使用信用卡透支取款时,透支部分的金额是需要计算两次手续费的。另一个多次错误的点在于判断金额是否满足所需取款的金额。正确的判断条件应该为手续费(如果是跨行取款、或者是透支取款)加上所需取款金额小于等于借记卡的余额或者信用卡的余额加信用卡的透支额度。还有一个难点在于对金额不足判断和取款后余额的计算。因为在7-5中,多了信用卡、透支情况、跨行取款情况,所以要进行分类讨论。分别计算在使用借记卡(无法透支)的非跨行取款和跨行取款,使用信用卡透支情况下跨行取款和非跨行取款,透支情况下跨行取款和非跨行取款六种情况。需要理顺情况和关系后才能正确完成题目。
7-4代码如下:
import java.util.*; class ChinaUnionPay { private Bank[] bank; public ChinaUnionPay() { } public ChinaUnionPay(Bank[] bank) { this.bank = bank; } } class Bank { private User[] users; private String bankName; public Bank() { } public Bank(User[] users, String bankName) { this.users = users; this.bankName = bankName; } public String getBankName() { return bankName; } public void setBankName(String bankName) { this.bankName = bankName; } public User[] getUsers() { return users; } public void setUsers(User[] users) { this.users = users; } } class User { private Account[] accounts; private String username; public User() { } public User(Account[] accounts, String username) { this.accounts = accounts; this.username = username; } public Account[] getAccounts() { return accounts; } public void setAccounts(Account[] accounts) { this.accounts = accounts; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } } class Account { private Card[] cards; private String accountNum; private double balance; public Account(String accountNum, double balance) { this.accountNum = accountNum; this.balance = balance; } public Account(Card[] cards, String accountNum, double balance) { this.cards = cards; this.accountNum = accountNum; this.balance = balance; } public Card[] getCards() { return cards; } public void setCards(Card[] cards) { this.cards = cards; } public double getBalance() { return balance; } public void setBalance(double balance) { this.balance = balance; } public double showBalance(){ return balance; } } class Card { private String cardNumber; private String password; public Card() { } public Card(String cardNumber, String password) { this.cardNumber = cardNumber; this.password = password; } public String getCardNumber() { return cardNumber; } public void setCardNumber(String cardNumber) { this.cardNumber = cardNumber; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } class ATM { private String number; String belongToBank; public ATM() { } public ATM(String number, String belongToBank) { this.number = number; this.belongToBank = belongToBank; } public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } public String getBelongToBank() { return belongToBank; } public void setBelongToBank(String belongToBank) { this.belongToBank = belongToBank; } } class Action { private Bank[] banks; private ATM[] atms; public Action() { } public Action(Bank[] banks, ATM[] atms) { this.banks = banks; this.atms = atms; } public boolean checkCardExist(String cardNumber){ int i = 0; int j = 0; int k = 0; int m = 0; int n = 0; for(i = 0; i < banks.length; i++){ for(j = 0; j < banks[i].getUsers().length; j++){ for(k = 0; k < banks[i].getUsers()[j].getAccounts().length; k++){ for(m = 0; m < banks[i].getUsers()[j].getAccounts()[k].getCards().length; m++){ if(cardNumber.equals(banks[i].getUsers()[j].getAccounts()[k].getCards()[m].getCardNumber())){ return true; } } } } } return false; } public boolean checkAtmExist(String atmNumber){ int s = 0; while(s < atms.length){ if(atmNumber.equals(atms[s].getNumber())){ return true; } s++; } return false; } public boolean checkCardPassword(String cardPassword){ String str = "88888888"; if(cardPassword.equals(str)){ return true; } else { return false; } } public boolean checkBalance(String cardNumber, String money) { double money_s = Double.parseDouble(money); int i = 0; int j = 0; int k = 0; int m = 0; int n = 0; for(i = 0; i < banks.length; i++){ for(j = 0; j < banks[i].getUsers().length; j++){ for(k = 0; k < banks[i].getUsers()[j].getAccounts().length; k++){ for(m = 0; m < banks[i].getUsers()[j].getAccounts()[k].getCards().length; m++){ if(cardNumber.equals(banks[i].getUsers()[j].getAccounts()[k].getCards()[m].getCardNumber())){ if(money_s > banks[i].getUsers()[j].getAccounts()[k].showBalance()){ return false; } } } } } } return true; } public boolean checkInterBankAction(String cardNumber, String atmNumber){ int atmNum = Integer.parseInt(atmNumber) - 1; int i = 0; int j = 0; int k = 0; int m = 0; int n = 0; for(i = 0; i < banks.length; i++){ for(j = 0; j < banks[i].getUsers().length; j++){ for(k = 0; k < banks[i].getUsers()[j].getAccounts().length; k++){ for(m = 0; m < banks[i].getUsers()[j].getAccounts()[k].getCards().length; m++){ if(cardNumber.equals(banks[i].getUsers()[j].getAccounts()[k].getCards()[m].getCardNumber())){ if(!atms[atmNum].getBelongToBank().equals(banks[i].getBankName())){ return false; } } } } } } return true; } public void showBalance(String cardNumber){ int i = 0; int j = 0; int k = 0; int m = 0; int n = 0; loop:for(i = 0; i < banks.length; i++){ for(j = 0; j < banks[i].getUsers().length; j++){ for(k = 0; k < banks[i].getUsers()[j].getAccounts().length; k++){ for(m = 0; m < banks[i].getUsers()[j].getAccounts()[k].getCards().length; m++){ if(cardNumber.equals(banks[i].getUsers()[j].getAccounts()[k].getCards()[m].getCardNumber())){ System.out.println("¥"+String.format("%.2f",banks[i].getUsers()[j].getAccounts()[k].showBalance())); break loop; } } } } } } public void deposit(String cardNumber,double money,String atmNumber){ int i = 0; int j = 0; int k = 0; int m = 0; int n = 0; loop:for(i = 0; i < banks.length; i++){ for(j = 0; j < banks[i].getUsers().length; j++){ for(k = 0; k < banks[i].getUsers()[j].getAccounts().length; k++){ for(m = 0; m < banks[i].getUsers()[j].getAccounts()[k].getCards().length; m++){ if(cardNumber.equals(banks[i].getUsers()[j].getAccounts()[k].getCards()[m].getCardNumber())){ banks[i].getUsers()[j].getAccounts()[k].setBalance(banks[i].getUsers()[j].getAccounts()[k].showBalance() - money); System.out.println(banks[i].getUsers()[j].getUsername()+"在"+banks[i].getBankName()+"的"+atmNumber+"号ATM机上存款¥"+String.format("%.2f",-money)); System.out.println("当前余额为¥"+String.format("%.2f",banks[i].getUsers()[j].getAccounts()[k].showBalance())); break loop; } } } } } } public void withdraw(String cardNumber,double money,String atmNumber){ int i = 0; int j = 0; int k = 0; int m = 0; int n = 0; loop:for(i = 0; i < banks.length; i++){ for(j = 0; j < banks[i].getUsers().length; j++){ for(k = 0; k < banks[i].getUsers()[j].getAccounts().length; k++){ for(m = 0; m < banks[i].getUsers()[j].getAccounts()[k].getCards().length; m++){ if(cardNumber.equals(banks[i].getUsers()[j].getAccounts()[k].getCards()[m].getCardNumber())){ banks[i].getUsers()[j].getAccounts()[k].setBalance(banks[i].getUsers()[j].getAccounts()[k].showBalance() - money); System.out.println(banks[i].getUsers()[j].getUsername()+"在"+banks[i].getBankName()+"的"+atmNumber+"号ATM机上取款¥"+String.format("%.2f",money)); System.out.println("当前余额为¥"+String.format("%.2f",banks[i].getUsers()[j].getAccounts()[k].showBalance())); break loop; } } } } } } } public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); Card card01 = new Card("6217000010041315709","88888888"); Card card02 = new Card("6217000010041315715","88888888"); Card[] cards1 = new Card[2]; cards1[0] = card01; cards1[1] = card02; Account account01 = new Account(cards1,"3217000010041315709 ",10000.00); Card card03 = new Card("6217000010041315718","88888888"); Card[] cards2 = new Card[1]; cards2[0] = card03; Account account02 = new Account(cards2,"3217000010041315715",10000.00); Account[] accounts1 = new Account[2]; accounts1[0] = account01; accounts1[1] = account02; User user1 = new User(accounts1,"杨过"); Card card04 = new Card("6217000010051320007","88888888"); Card[] cards3 = new Card[1]; cards3[0] = card04; Account account03 = new Account(cards3,"3217000010051320007",10000.00); Account[] accounts2 = new Account[1]; accounts2[0] = account03; User user2 = new User(accounts2,"郭靖"); Card card05 = new Card("6222081502001312389","88888888"); Card[] cards4 = new Card[1]; cards4[0] = card05; Account account04 = new Account(cards4,"3222081502001312389",10000.00); Card card06 = new Card("6222081502001312390","88888888"); Card[] cards5 = new Card[1]; cards5[0] = card06; Account account05 = new Account(cards5,"3222081502001312390",10000.00); Card card07 = new Card("6222081502001312399","88888888"); Card card08 = new Card("6222081502001312400","88888888"); Card[] cards6 = new Card[2]; cards6[0] = card07; cards6[1] = card08; Account account06 = new Account(cards6,"3222081502001312399",10000.00); Account[] accounts3 = new Account[3]; accounts3[0] = account04; accounts3[1] = account05; accounts3[2] = account06; User user3 = new User(accounts3,"张无忌"); Card card09 = new Card("6222081502051320785","88888888"); Card[] cards7 = new Card[1]; cards7[0] = card09; Account account07 = new Account(cards7,"3222081502051320785",10000.00); Card card010 = new Card("6222081502051320786","88888888"); Card[] cards8 = new Card[1]; cards8[0] = card010; Account account08 = new Account(cards8,"3222081502051320786",10000.00); Account[] accounts4 = new Account[2]; accounts4[0] = account07; accounts4[1] = account08; User user4 = new User(accounts4,"韦小宝"); User[] users1 = new User[2]; users1[0] = user1; users1[1] = user2; User[] users2 = new User[2]; users2[0] = user3; users2[1] = user4; Bank bank1 = new Bank(users1,"中国建设银行"); Bank bank2 = new Bank(users2,"中国工商银行"); Bank[] banks = new Bank[2]; banks[0] = bank1; banks[1] = bank2; ATM atm01 = new ATM("01","中国建设银行"); ATM atm02 = new ATM("02","中国建设银行"); ATM atm03 = new ATM("03","中国建设银行"); ATM atm04 = new ATM("04","中国建设银行"); ATM atm05 = new ATM("05","中国工商银行"); ATM atm06 = new ATM("06","中国工商银行"); ATM[] atms = new ATM[6]; atms[0] = atm01; atms[1] = atm02; atms[2] = atm03; atms[3] = atm04; atms[4] = atm05; atms[5] = atm06; Action action = new Action(banks,atms); String str = "null"; while(!str.equals("#")){ str = in.nextLine(); String[] inputStr= str.split("\\s+"); if(inputStr.length > 1) { if (!action.checkCardExist(inputStr[0])) { System.out.println("Sorry,this card does not exist."); break; } if (!action.checkAtmExist(inputStr[2])){ System.out.println("Sorry,the ATM's id is wrong."); break; } if (!action.checkCardPassword(inputStr[1])){ System.out.println("Sorry,your password is wrong."); break; } if (!action.checkBalance(inputStr[0],inputStr[3])){ System.out.println("Sorry,your account balance is insufficient."); break; } if (!action.checkInterBankAction(inputStr[0],inputStr[2])){ System.out.println("Sorry,cross-bank withdrawal is not supported."); break; } double money = Double.parseDouble(inputStr[3]); if(money < 0) { action.deposit(inputStr[0], money, inputStr[2]); } else { action.withdraw(inputStr[0], money, inputStr[2]); } } else { action.showBalance(inputStr[0]); } } } }View Code
7-5代码如下:
import java.util.*; class ChinaUnionPay { private Bank[] bank; } class Bank { private String bankName;//银行名 public Bank(String bankName) { this.bankName = bankName; } public String getBankName() { return bankName; } public void setBankName(String bankName) { this.bankName = bankName; } } class User { private Bank bank;//所属银行 private String username;//客户名字 public User(Bank bank, String username) { this.bank = bank; this.username = username; } public Bank getBank() { return bank; } public void setBank(Bank bank) { this.bank = bank; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } } class Account { private String accountNum;//账户账号 private double balance;//账户余额 public Account(String accountNum, double balance) { this.accountNum = accountNum; this.balance = balance; } public String getAccountNum() { return accountNum; } public void setAccountNum(String accountNum) { this.accountNum = accountNum; } public double getBalance() { return balance; } public void setBalance(double balance) { this.balance = balance; } } /** * 银行卡 */ class Card { private String cardNumber;//卡号 private String password;//密码 private String kind;//种类 private Account account;//所属账户 private Bank bank;//所属银行 private User user;//持有者 public Card(String cardNumber, String password, String kind, Account account, Bank bank, User user) { this.cardNumber = cardNumber; this.password = password; this.kind = kind; this.account = account; this.bank = bank; this.user = user; } public String getCardNumber() { return cardNumber; } public void setCardNumber(String cardNumber) { this.cardNumber = cardNumber; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getKind() { return kind; } public void setKind(String kind) { this.kind = kind; } public Account getAccount() { return account; } public void setAccount(Account account) { this.account = account; } public Bank getBank() { return bank; } public void setBank(Bank bank) { this.bank = bank; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } } class ATM { private String number;//ATM机的编号 private Bank bank;//所属银行 public ATM(String number, Bank bank) { this.number = number; this.bank = bank; } public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } public Bank getBank() { return bank; } public void setBank(Bank bank) { this.bank = bank; } } class Action{ private Card[] cards;//所有银行卡 private ATM[] atms;//所有ATM机 public Action(Card[] cards, ATM[] atms) { this.cards = cards; this.atms = atms; } /** * 检查卡号是否存在 * @param cardNumber * @return */ public boolean checkCardExist(String cardNumber){ int s = 0; while(s < cards.length){ if(cardNumber.equals(cards[s].getCardNumber())){ return true; } s++; } return false; } /** * 检查ATM机是否存在 * @param atmNumber * @return */ public boolean checkAtmExist(String atmNumber){ int s = 0; while(s < atms.length){ if(atmNumber.equals(atms[s].getNumber())){ return true; } s++; } return false; } /** * 检查银行卡密码是否匹配 * @param cardPassword * @return */ public boolean checkCardPassword(String cardPassword){ String str = "88888888"; if(cardPassword.equals(str)){ return true; } else { return false; } } /** * 检查账户余额是否支持取款 * @param cardNumber * @param money * @param atmNumber * @return */ public boolean checkBalance(String cardNumber, double money,String atmNumber) { int atmNum = Integer.parseInt(atmNumber) - 1; int s = 0; while(s < cards.length){ if(cardNumber.equals(cards[s].getCardNumber()) && cards[s].getKind().equals("信用卡")){ if(!cards[s].getBank().getBankName().equals(atms[atmNum].getBank().getBankName()) && cards[s].getBank().getBankName().equals("中国建设银行")) { if (cards[s].getAccount().getBalance() > 0) { if (money <= cards[s].getAccount().getBalance()) { if(cards[s].getAccount().getBalance() - money - money * 0.02 >= -50000){ return true; } } else { if((cards[s].getAccount().getBalance() - money) * 1.05 - money * 0.02 >= -50000){ return true; } } } else { if(cards[s].getAccount().getBalance() - money * 1.05 - money * 0.02 >= -50000){ return true; } } } if(!cards[s].getBank().getBankName().equals(atms[atmNum].getBank().getBankName()) && cards[s].getBank().getBankName().equals("中国工商银行")){ if (cards[s].getAccount().getBalance() > 0) { if (money <= cards[s].getAccount().getBalance()) { if(cards[s].getAccount().getBalance() - money - money * 0.03 >= -50000){ return true; } } else { if((cards[s].getAccount().getBalance() - money) * 1.05 - money * 0.03 >= -50000){ return true; } } } else { if(cards[s].getAccount().getBalance() - money * 1.05 - money * 0.03 >= -50000){ return true; } } } if(!cards[s].getBank().getBankName().equals(atms[atmNum].getBank().getBankName()) && cards[s].getBank().getBankName().equals("中国农业银行")){ if (cards[s].getAccount().getBalance() > 0) { if (money <= cards[s].getAccount().getBalance()) { if(cards[s].getAccount().getBalance() - money - money * 0.04 >= -50000){ return true; } } else { if((cards[s].getAccount().getBalance() - money) * 1.05 - money * 0.04 >= -50000){ return true; } } } else { if(cards[s].getAccount().getBalance() - money * 1.05 - money * 0.04 >= -50000){ return true; } } } if(cards[s].getBank().getBankName().equals(atms[atmNum].getBank().getBankName())){ if (cards[s].getAccount().getBalance() > 0) { if (money <= cards[s].getAccount().getBalance()) { if(cards[s].getAccount().getBalance() - money >= -50000){ return true; } } else { if((cards[s].getAccount().getBalance() - money) * 1.05 >= -50000){ return true; } } } else { if(cards[s].getAccount().getBalance() - money * 1.05 >= -50000){ return true; } } } } else if(cardNumber.equals(cards[s].getCardNumber()) && cards[s].getKind().equals("借记卡")){ if(!cards[s].getBank().getBankName().equals(atms[atmNum].getBank().getBankName()) && cards[s].getBank().getBankName().equals("中国建设银行")){ if(money + money * 0.02 <= cards[s].getAccount().getBalance()){ return true; } } if(!cards[s].getBank().getBankName().equals(atms[atmNum].getBank().getBankName()) && cards[s].getBank().getBankName().equals("中国工商银行")){ if(money + money * 0.03 <= cards[s].getAccount().getBalance()){ return true; } } if(!cards[s].getBank().getBankName().equals(atms[atmNum].getBank().getBankName()) && cards[s].getBank().getBankName().equals("中国农业银行")){ if(money + money * 0.04 <= cards[s].getAccount().getBalance()){ return true; } } if(cards[s].getBank().getBankName().equals(atms[atmNum].getBank().getBankName())){ if(money <= cards[s].getAccount().getBalance()){ return true; } } } s++; } return false; } /** * 显示账户余额 * @param cardNumber */ public void showBalance(String cardNumber){ int s = 0; while(s < cards.length){ if(cardNumber.equals(cards[s].getCardNumber())){ System.out.println("业务:查询余额 ¥"+String.format("%.2f",cards[s].getAccount().getBalance())); } s++; } } /** * 存款 * @param cardNumber * @param money * @param atmNumber */ public void deposit(String cardNumber,double money,String atmNumber){ int s = 0; while(s < cards.length){ if(cardNumber.equals(cards[s].getCardNumber())){ cards[s].getAccount().setBalance(cards[s].getAccount().getBalance() - money); System.out.println("业务:取款 "+cards[s].getUser().getUsername()+"在"+cards[s].getBank().getBankName()+"的"+atmNumber+"上存款¥"+(-money)); System.out.println("当前余额为¥"+String.format("%.2f",cards[s].getAccount().getBalance())); } s++; } } /** * 取款 * @param cardNumber * @param money * @param atmNumber */ public void withdraw(String cardNumber,double money,String atmNumber) { int atmNum = Integer.parseInt(atmNumber) - 1; int s = 0; while(s < cards.length){ if(cardNumber.equals(cards[s].getCardNumber())){ if(!cards[s].getBank().getBankName().equals(atms[atmNum].getBank().getBankName()) && atms[atmNum].getBank().getBankName().equals("中国建设银行")) { if (cards[s].getAccount().getBalance() > 0) { if (money <= cards[s].getAccount().getBalance()) { cards[s].getAccount().setBalance(cards[s].getAccount().getBalance() - money - money * 0.02); } else { cards[s].getAccount().setBalance((cards[s].getAccount().getBalance() - money) * 1.05 - money * 0.02); } } else { cards[s].getAccount().setBalance(cards[s].getAccount().getBalance() - money * 1.05 - money * 0.02); } System.out.println("业务:取款 "+cards[s].getUser().getUsername()+"在"+atms[atmNum].getBank().getBankName()+"的"+atms[atmNum].getNumber()+"号ATM机上取款¥"+String.format("%.2f",money)); System.out.println("当前余额为¥"+String.format("%.2f",cards[s].getAccount().getBalance())); } if(!cards[s].getBank().getBankName().equals(atms[atmNum].getBank().getBankName()) && atms[atmNum].getBank().getBankName().equals("中国工商银行")){ if (cards[s].getAccount().getBalance() > 0) { if (money <= cards[s].getAccount().getBalance()) { cards[s].getAccount().setBalance(cards[s].getAccount().getBalance() - money - money * 0.03); } else { cards[s].getAccount().setBalance((cards[s].getAccount().getBalance() - money) * 1.05 - money * 0.03); } } else { cards[s].getAccount().setBalance(cards[s].getAccount().getBalance() - money * 1.05 - money * 0.03); } System.out.println("业务:取款 "+cards[s].getUser().getUsername()+"在"+atms[atmNum].getBank().getBankName()+"的"+atms[atmNum].getNumber()+"号ATM机上取款¥"+String.format("%.2f",money)); System.out.println("当前余额为¥"+String.format("%.2f",cards[s].getAccount().getBalance())); } if(!cards[s].getBank().getBankName().equals(atms[atmNum].getBank().getBankName()) && atms[atmNum].getBank().getBankName().equals("中国农业银行")){ if (cards[s].getAccount().getBalance() > 0) { if (money <= cards[s].getAccount().getBalance()) { cards[s].getAccount().setBalance(cards[s].getAccount().getBalance() - money - money * 0.04); } else { cards[s].getAccount().setBalance((cards[s].getAccount().getBalance() - money) * 1.05 - money * 0.04); } } else { cards[s].getAccount().setBalance(cards[s].getAccount().getBalance() - money * 1.05 - money * 0.04); } System.out.println("业务:取款 "+cards[s].getUser().getUsername()+"在"+atms[atmNum].getBank().getBankName()+"的"+atms[atmNum].getNumber()+"号ATM机上取款¥"+String.format("%.2f",money)); System.out.println("当前余额为¥"+String.format("%.2f",cards[s].getAccount().getBalance())); } if(cards[s].getBank().getBankName().equals(atms[atmNum].getBank().getBankName())){ if (cards[s].getAccount().getBalance() > 0) { if (money <= cards[s].getAccount().getBalance()) { cards[s].getAccount().setBalance(cards[s].getAccount().getBalance() - money); } else { cards[s].getAccount().setBalance((cards[s].getAccount().getBalance() - money) * 1.05 ); } } else { cards[s].getAccount().setBalance(cards[s].getAccount().getBalance() - money * 1.05); } System.out.println("业务:取款 "+cards[s].getUser().getUsername()+"在"+atms[atmNum].getBank().getBankName()+"的"+atms[atmNum].getNumber()+"号ATM机上取款¥"+String.format("%.2f",money)); System.out.println("当前余额为¥"+String.format("%.2f",cards[s].getAccount().getBalance())); } } s++; } } } public class Main { public static void main(String[] args) { /** * 创建银行 */ Bank bank1 = new Bank("中国建设银行"); Bank bank2 = new Bank("中国工商银行"); Bank bank3 = new Bank("中国农业银行"); /** * 创建ATM机对象 * */ ATM atm01 = new ATM("01",bank1); ATM atm02 = new ATM("02",bank1); ATM atm03 = new ATM("03",bank1); ATM atm04 = new ATM("04",bank1); ATM atm05 = new ATM("05",bank2); ATM atm06 = new ATM("06",bank2); ATM atm07 = new ATM("07",bank3); ATM atm08 = new ATM("08",bank3); ATM atm09 = new ATM("09",bank3); ATM atm10 = new ATM("10",bank3); ATM atm11 = new ATM("11",bank3); ATM[] atms = new ATM[11]; atms[0] = atm01; atms[1] = atm02; atms[2] = atm03; atms[3] = atm04; atms[4] = atm05; atms[5] = atm06; atms[6] = atm07; atms[7] = atm08; atms[8] = atm09; atms[9] = atm10; atms[10] = atm11; /** * 初始化银行、用户、账户、银行卡信息 */ User user1 = new User(bank1,"杨过"); Account account01 = new Account("3217000010041315709",10000.00); Card card01 = new Card("6217000010041315709","88888888","借记卡",account01,bank1,user1); Card card02 = new Card("6217000010041315715","88888888","借记卡",account01,bank1,user1); Account account02 = new Account("3217000010041315715",10000.00); Card card03 = new Card("6217000010041315718","88888888","借记卡",account02,bank1,user1); User user2 = new User(bank1,"郭靖"); Account account03 = new Account("3217000010051320007",10000.00); Card card04 = new Card("6217000010051320007","88888888","借记卡",account03,bank1,user2); User user3 = new User(bank2,"张无忌"); Account account04 = new Account("3222081502001312389",10000.00); Card card05 = new Card("6222081502001312389","88888888","借记卡",account04,bank2,user3); Account account05 = new Account("3222081502001312390",10000.00); Card card06 = new Card("6222081502001312390","88888888","借记卡",account05,bank2,user3); Account account06 = new Account("3222081502001312399",10000.00); Card card07 = new Card("6222081502001312399","88888888","借记卡",account06,bank2,user3); Card card08 = new Card("6222081502001312400","88888888","借记卡",account06,bank2,user3); User user4 = new User(bank2,"韦小宝"); Account account07 = new Account("3222081502051320785",10000.00); Card card09 = new Card("6222081502051320785","88888888","借记卡",account07,bank2,user4); Account account08 = new Account("3222081502051320786",10000.00); Card card10 = new Card("6222081502051320786","88888888","借记卡",account08,bank2,user4); User user5 = new User(bank1,"张三丰"); Account account09 = new Account("3640000010045442002",10000.00); Card card11 = new Card("6640000010045442002","88888888","信用卡",account09,bank1,user5); Card card12 = new Card("6640000010045442003","88888888","信用卡",account09,bank1,user5); User user6 = new User(bank2,"令狐冲"); Account account10 = new Account("3640000010045441009",10000.00); Card card13 = new Card("6640000010045441009","88888888","信用卡",account10,bank2,user6); User user7 = new User(bank3,"乔峰"); Account account11 = new Account("3630000010033431001",10000.00); Card card14 = new Card("6630000010033431001","88888888","信用卡",account11,bank3,user7); User user8 = new User(bank3,"洪七公"); Account account12 = new Account("3630000010033431008",10000.00); Card card15 = new Card("6630000010033431008","88888888","信用卡",account12,bank3,user8); Card[] cards = new Card[15]; cards[0] = card01; cards[1] = card02; cards[2] = card03; cards[3] = card04; cards[4] = card05; cards[5] = card06; cards[6] = card07; cards[7] = card08; cards[8] = card09; cards[9] = card10; cards[10] = card11; cards[11] = card12; cards[12] = card13; cards[13] = card14; cards[14] = card15; Action action = new Action(cards,atms); Scanner in = new Scanner(System.in); String str = "null"; while(!str.equals("#")){ str = in.nextLine(); String[] inputStr= str.split("\\s+"); if(inputStr.length > 1) { if (!action.checkCardExist(inputStr[0])) { System.out.println("Sorry,this card does not exist.");//判断卡号是否存在 break; } if (!action.checkAtmExist(inputStr[2])){ System.out.println("Sorry,the ATM's id is wrong.");//判断ATM是否存在 break; } if (!action.checkCardPassword(inputStr[1])){ System.out.println("Sorry,your password is wrong.");//判断密码是否匹配 break; } double money = Double.parseDouble(inputStr[3]); if (!action.checkBalance(inputStr[0],money,inputStr[2])){ System.out.println("Sorry,your account balance is insufficient.");//判断余额是否正常 break; } if(money < 0) { action.deposit(inputStr[0], money, inputStr[2]);//存款 } else { action.withdraw(inputStr[0], money, inputStr[2]);//取款 } } else { action.showBalance(inputStr[0]);//显示账户余额 } } } }View Code
总结:
通过这三次题目集的练习后,反应出比较多的问题。特别是第六次题目集,在训练过程中,对类的设计总是摸不着头脑,难以准确把握类与类之间的关系,以及在对不同类中方法的调用。比如第六次题目集的7-3题,对水纹信息的处理中,没有厘清业务类和实体类之间的关系和调用,且在设计的时候没有满足单一职责原则。反映出对于设计的原则只是知道浅显的概念,没用理解透彻,在题目中难以运用。在第五次题目集中,有较多的正则表达式训练,但涉及到的并不完全,正则表达式没有熟练掌握,记忆不清淅。
我认为问题最大的还是在第四次题目集的训练过程中,没有合理安排好时间,在题目集关闭的前两三天才开始动手训练,由于7-1题目难度的跃升,导致没有空余时间来完成7-1,甚至没有仔细地研究题目,题目集就关闭了。
这给我一个很大的警示:一定要合理安排时间,多进行有效的训练,不要将任务全部堆积在最后的期限来完成,如果一拖再拖,结果往往不尽如人意。另外我认为自己在学习中,还要多注重设计上理解和运用,课堂上听懂了课下却不一定能合理地运用,有点像花架子,徒有其表。但设计还是一个慢慢积累经验的过程,切记戒骄戒躁,还需脚踏实地地学习。注重平常的训练,多思考,多回顾。
标签:总结,return,String,int,value,OOP,new,题目,public From: https://www.cnblogs.com/zhxjs/p/17364311.html