讲解:Cardholders、Web-CAT、Java、Java Statistics、、|

Project: Cardholders – Part 3 Page 1 of 7Deliverables:Your project files should be submitted to Web-CAT by the due date and time specified. Note thatthere is also an optional Skeleton Code assignment which will indicate level of coverage your testshave achieved (there is no late penalty since the skeleton code assignment is ungraded for thisproject). The files you submit to skeleton code assignment may be incomplete in the sense thatmethod bodies have at least a return statement if applicable or they may be essentially completedfiles. In order to avoid a late penalty for the project, you must submit your completed code files toWeb-CAT no later than 11:59 PM on the due date for the completed code assignment. If you areunable to submit via Web-CAT, you should e-mail your project Java files in a zip file to your TAbefore the deadline. The grades for the Completed Code submission will be determined by the teststhat you pass or fail in your test files and by the level of coverage attained in your source files as wellas usual correctness tests in Web-CAT.Files to submit to Web-CAT:Files from Cardholders - Part 1 Cardholder.java SapphireCardholder.java, SapphireCardholderTest.java DiamondCardholder.java, DiamondCardholderTest.java BlueDiamondCardholder.java, BlueDiamondCardholderTest.javaFiles in Cardholders - Part 2 CurrentBalanceComparator CardholderProcessor.java (add exception handling), CardholderProcessorTest.javaNew Files in Cardholders - Part 3 CardholdersPart3App.java java (add exception handling to Part2App), CardholdersPart3AppTest.java InvalidCategoryExceptionSpecifications – Use arrays inthis project; ArrayLists are notallowed!Overview: Cardholders - Part 3 is the third ofa three-part software project to process themonthly purchases made by Sapphire,Diamond, and Blue Diamond cardholders.The completed class hierarchy is shown in theUML class diagram at right. Part 3 of theproject focuses on handling exceptions that arethrown as a result of erroneous input from thecommand line or the data file. The mainmethod in the CardholdersPart3App class,which reads in the file name from thecommand line, will need handle aFileNotFoundException that may result from Project: Cardholders – Part 3 Page 2 of 7attempting to open the file (e.g., if the file does not exist). Also, the readCardholderFile method inCardholderProcessor will need to handle exceptions that occur while processing the data file, including anew exception called InvalidCategoryException.Cardholder, SapphireCardholder, DiamondCardholder, BlueDiamondCardholder,CurrentBalanceComparatorRequirements and Design: There are no changes to these classes from Part 2.CardholderProcessor.javaRequirements: The CardholderProcessor class provides methods for reading in the data file andgenerating the monthly report. The readCardholderFile method should redesigned to handleexceptions in the data. A “good” line of data results in a new element added the Cardholder array, and“bad” line of data results in the line + exception message being added the to the invalid records array.A new report method produces the Invalid Records Report.Design: The readCardholderFile method from Part 2 should be redesigned to handle exceptions.CardholderProcessor class has fields, a constructor, and methods as outlined below.Fields: no change from Part 2. Constructor: no change from Part 2. Methods: The readCardholderFile needs to be reworked and the generateInvalidRecordsReportmethod needs to be added. See Part 2 for the full description of other methods in this class.o readCardholderFile has no return value, accepts the data file name as a String, andthrows FileNotFoundException. If a FileNotFoundException occurs when attempting to openthe data file, it should be ignored in this method so that it can be handled in the calling method(i.e., main). If a line from the file is processed successfully, a Cardholder object of theappropriate category (subclass) is added to the Cardholder array field. However, when anexception occurs as a result from erroneous data in a line read from the file, it should becaught and handled as follows. The exception message should be concatenated to the line andthen the resulting String should be added to the invalid records array field in the class. Thetwo exceptions that should be caught in this method are the InvalidCategoryException(described below) and the NumberFormatException. Note that the InvalidCategoryExceptionmust be explicitly thrown by your code if the category is not 1, 2, or 3; whereas, theNumberFormatException will be thrown automatically if the item scanned in the line from thefile is not a double when Double.parseDouble expects it to be a double.o generateInvalidRecordsReport processes the invalid records array to produce theInvalid Records Report and then returns the report as String. See the example result near theend of the output for CardholdersPart3App that begins on page 4 and ends on page 6.Code and Test: See examples of exception handling in the text and the class notes. Downloadcardholder_data_3_exceptions.txt from the assignment page in Canvas to test yourprogram. Your JUnit test methods should force the exceptions described above to thrown and caught. Project: Cardholders – Part 3 Page 3 of 7Since the readCardholderFile method will propagate the FileNotFoundException if the file is not foundwhen the Scanner is created to read the file, your test method could catch this exception to check that itwas thrown.InvalidCategoryException.javaRequirements and Design: The InvalidCategoryException class defines a new subclass of theException class. The constructor invokes the super constructor with the message: *** invalidcategory ***. See examples of creating user defined in from text and class notes.CardholdersPart3App.javaRequirements: The CardholdersPart3App class contains the main method for running the program. Inaddition to the specifications in Part 2, the main method should be modified as indicated below.Design: The CardholdersPart3App class is the driver class and has a main method described below.o main accepts a file name as a command line argument, then within a try block, creates aCardholderProcessor object, and then invokes its methods to read the file and process thereward records and then to generate and print the four reports as shown in the example outputbeginning on page 4. If no command line argument is provided, the program should indicatethis and end as shown in the first example output on page 4. If an FileNotFoundException isthrown in the readCardholderFile method in the CardholderProcessor class, it should be caughtin the catch block of the try statement. The catch block should print a message (“***Attempted to read file: ” along with the exception’s message). For example, if the user entered“nofile.txt” as the command line argument and this file does not exit, then the Run I/O injGRASP would look like the following (this is also repeated in the example output beginningon page 4). Note that since the main method is catching FileNotFoundException, it no longerneeds the throws clause in its declaration.MM?M ----jGRASP exec: java CardholdersPart3App nofile.txtMM§M *** Attempted to read file: nofile.txt (No such file or directory)MM§MMM?M ----jGRASP: operation complete.Code and Test: See examples of exception handling in the text and the class notes. Downloadcardholder_data_3_exceptions.txt from the assignment page in Canvas to test yourprogram. One of your JUnit test methods should call your main method wiCardholders留学生作业代写、代做Web-CAT作业、代写Java程序作业、代做Java语言作业 代写留学生 Sth an argument this is not avalid file name to ensure that your catch block is covered. See “Code and Test” forCardholdersPart2App in Part 2 to see how to invoke your main method.Project: Cardholders – Part 3 Page 4 of 7Example OutputThree separate runs are shown below: (1) one with no command line argument, (2) one with an invalidfile name as command line argument, and (3) one with valid file name as command line argument.MMM ----jGRASP exec: java CardholdersPart3AppMM§MFile name expected as command line argument.MM§MProgram ending.MM§MMMM ----jGRASP: operation complete.MMM ----jGRASP exec: java CardholdersPart3App nofile.txtMM§M *** Attempted to read file: nofile.txt (No such file or directory)MM§MMMM ----jGRASP: operation complete.MMM ----jGRASP exec: java CardholdersPart3App cardholder_data_3_exceptions.txtMM§M----------------------------MM§MMonthly Cardholder ReportMM§M----------------------------MM§MDiamond CardholderMM§MAcctNo/Name: 10002 Jones, PatMM§MPrevious Balance: $1,200.00MM§MPayment: ($100.00)MM§MInterest: $11.00MM§MNew Purchases: $473.10MM§MCurrent Balance: $1,584.10MM§MMinimum Payment: $47.52MM§MPurchase Points: 1,419MM§M(includes 5.0% discount rate applied to New Purchases)MM§MMM§MBlue Diamond CardholderMM§MAcctNo/Name: 10003 King, KellyMM§MPrevious Balance: $1,300.00MM§MPayment: ($150.00)MM§MInterest: $11.50MM§MNew Purchases: $538.20MM§MCurrent Balance: $1,699.70MM§MMinimum Payment: $50.99MM§MPurchase Points: 2,690MM§M(includes 10.0% discount rate applied to New Purchases)MM§MMM§MSapphire CardholderMM§MAcctNo/Name: 10001 Smith, SamMM§MPrevious Balance: $1,100.00MM§MPayment: ($200.00)MM§MInterest: $9.00MM§MNew Purchases: $548.00MM§MCurrent Balance: $1,457.00MM§MMinimum Payment: $43.71MM§MPurchase Points: 548MM§MMM§MBlue Diamond CardholderMM§MAcctNo/Name: 10004 Jenkins, JordanMM§MPrevious Balance: $1,400.00MM§MPayment: ($1,400.00)MM§MInterest: $0.00Project: Cardholders– Part 3 Page5 of7MM§MNew Purchases: $9,000.00MM§MCurrent Balance: $9,000.00MM§MMinimum Payment: $270.00MM§MPurchase Points: 47,500MM§M(includes 10.0% discount rate applied to New Purchases)MM§M(includes 2,500 bonus points added to Purchase Points)MM§MMM§M--------------------------------------MM§MMonthly Cardholder Report (by Name)MM§M--------------------------------------MM§MBlue Diamond CardholderMM§MAcctNo/Name: 10004 Jenkins, JordanMM§MPrevious Balance: $1,400.00MM§MPayment: ($1,400.00)MM§MInterest: $0.00MM§MNew Purchases: $9,000.00MM§MCurrent Balance: $9,000.00MM§MMinimum Payment: $270.00MM§MPurchase Points: 47,500MM§M(includes 10.0% discount rate applied to New Purchases)MM§M(includes 2,500 bonus points added to Purchase Points)MM§MMM§MDiamond CardholderMM§MAcctNo/Name: 10002 Jones, PatMM§MPrevious Balance: $1,200.00MM§MPayment: ($100.00)MM§MInterest: $11.00MM§MNew Purchases: $473.10MM§MCurrent Balance: $1,584.10MM§MMinimum Payment: $47.52MM§MPurchase Points: 1,419MM§M(includes 5.0% discount rate applied to New Purchases)MM§MMM§MBlue Diamond CardholderMM§MAcctNo/Name: 10003 King, KellyMM§MPrevious Balance: $1,300.00MM§MPayment: ($150.00)MM§MInterest: $11.50MM§MNew Purchases: $538.20MM§MCurrent Balance: $1,699.70MM§MMinimum Payment: $50.99MM§MPurchase Points: 2,690MM§M(includes 10.0% discount rate applied to New Purchases)MM§MMM§MSapphire CardholderMM§MAcctNo/Name: 10001 Smith, SamMM§MPrevious Balance: $1,100.00MM§MPayment: ($200.00)MM§MInterest: $9.00MM§MNew Purchases: $548.00MM§MCurrent Balance: $1,457.00MM§MMinimum Payment: $43.71MM§MPurchase Points: 548MM§MMM§M---------------------------------------MM§MMonthly Cardholder Report (by Current Balance)MM§M---------------------------------------MM§MBlue Diamond CardholderMM§MAcctNo/Name: 10004 Jenkins, JordanMM§MPrevious Balance: $1,400.00Project: Cardholders – Part 3 Page 6 of 7MM§MPayment: ($1,400.00)MM§MInterest: $0.00MM§MNew Purchases: $9,000.00MM§MCurrent Balance: $9,000.00MM§MMinimum Payment: $270.00MM§MPurchase Points: 47,500MM§M(includes 10.0% discount rate applied to New Purchases)MM§M(includes 2,500 bonus points added to Purchase Points)MM§MMM§MBlue Diamond CardholderMM§MAcctNo/Name: 10003 King, KellyMM§MPrevious Balance: $1,300.00MM§MPayment: ($150.00)MM§MInterest: $11.50MM§MNew Purchases: $538.20MM§MCurrent Balance: $1,699.70MM§MMinimum Payment: $50.99MM§MPurchase Points: 2,690MM§M(includes 10.0% discount rate applied to New Purchases)MM§MMM§MDiamond CardholderMM§MAcctNo/Name: 10002 Jones, PatMM§MPrevious Balance: $1,200.00MM§MPayment: ($100.00)MM§MInterest: $11.00MM§MNew Purchases: $473.10MM§MCurrent Balance: $1,584.10MM§MMinimum Payment: $47.52MM§MPurchase Points: 1,419MM§M(includes 5.0% discount rate applied to New Purchases)MM§MMM§MSapphire CardholderMM§MAcctNo/Name: 10001 Smith, SamMM§MPrevious Balance: $1,100.00MM§MPayment: ($200.00)MM§MInterest: $9.00MM§MNew Purchases: $548.00MM§MCurrent Balance: $1,457.00MM§MMinimum Payment: $43.71MM§MPurchase Points: 548MM§MMM§M-----------------------MM§MInvalid Records ReportMM§M-----------------------MM§M1;10005;Smith, Pam;110p.0;200.0;34.5;100.0;63.50;350.0 *** invalid numeric value ***MM§MMM§M4;00000;Williams,Pat;1000.0;0.0;34.5;100.0;63.50;300.0 *** invalid category ***MM§MMM§M3;10008;Jenkins, Jordan;1400.0;1400.0;5000.0;1000.0+;4000.0 *** invalid numeric value ***MM§MMM§M2;10006;Jones, Mat;1200.0;1-0.0;34.5;100.0;63.50;300.0 *** invalid numeric value ***MM§MMM§M3;10007;King, Kilby;1300.0;150.0;34.5;$100.0;63.50;300.0;100.0 *** invalid numeric value ***MM§MMM§MMMM ----jGRASP: operation complete.Project: Cardholders – Part 3 Page 7 of 7Notes1. This project assumes that you are reading each double value as a String using next() and then parsingit into a double with Double.parseDouble(...) as shown in the following example. . . . Double.parseDouble(myInput.next());This form of input will throw a java.lang.NumberFormatException if the value is not a double.If you are reading in each double value as a double using nextDouble(), for example . . . myInput.nextDouble();then a java.util.InputMismatchException will be thrown if the value read in is not a double.For this assignment, you should change your input to use Double.parseDouble(...) rather thannextDouble(), since Web-CAT is looking for NumberFormatException rather thanjava.util.InputMismatchException.2. If you are using the JUnit Assert.assertArrayEquals method to check two Cardholder arrays forequality, then the equals and hashCode methods must be implemented in your Cardholder class;that is, Assert.assertArrayEquals calls equals(Object obj) on each object in the array, so Cardholdermust have an equals method that overrides the one inherited from the Object class. If Cardholderdoes not override equals(Object obj), then the JUnit Assert.assertArrayEquals method will use theinherited equals(Object obj) method which means two Cardholder arrays will be equal only if they arealiases.Below is a simplified equals method and hashCode method you are free to use. public boolean equals(Object obj) { if (!(obj instanceof Cardholder)) { return false; } else { Cardholder c = (Cardholder) obj; return (name.equalsIgnoreCase(c.getName())); } } public int hashCode() { return 0; }转自:http://ass.3daixie.com/2018113010001289.html

你可能感兴趣的:(讲解:Cardholders、Web-CAT、Java、Java Statistics、、|)