Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Programming Language: Java . Please help! /* * Test_Customer.java * * This test driver will allow for batch testing of the Customer class. * *
Programming Language: Java . Please help!
/* * Test_Customer.java * * This test driver will allow for batch testing of the Customer class. * * The test cases here are limited & generalized. Consider adding test cases to more fully * test the validation and exception handling in the associated classes. Testing for grading will include * different and additional test cases. * * (c) 2017, Terri Davis (updated 03/11/18) */ public class Test_Customer { public static void main(String[] args) { /* * The following array holds the test cases. It may be enlarged as needed/desired. */ String[] dataArray = {"1111111,999999999,LastName,FirstName,0,false,false" // test case template }; /* * The enhanced for loop will take each String in the above array and call the buildCustomer * method, passing the array of individual data items. */ for(String candidate: dataArray) { String[] parts = candidate.split(","); buildCustomer(parts); } // end for loop } // end main /* * The individual data items will be extracted and converted (if necessary). The class constructor is called. * IF an exception is thrown, it is caught and a VERBOSE message is displayed to the errror output. * ELSE, the describeCustomer method of the newly instantiated object is output to System.out. */ private static void buildCustomer(String[] parts) { Customer nextCust; try { String nbr = parts[0]; String id = parts[1]; String lName = parts[2]; String fName = parts[3]; int lim = Integer.parseInt(parts[4]); boolean reUp = Boolean.parseBoolean(parts[5]); boolean futures = Boolean.parseBoolean(parts[6]); nextCust = new Customer(nbr, id, lName, fName, lim, reUp, futures); System.out.printf("%s%n", nextCust.describeCustomer( )); } // end try catch(CustomerException custErr) { System.err.printf("%s thrown%n%s%n", custErr.getClass( ).getName( ), custErr.getMessage( )); } // end catch CustomerException } // end buildCustomer } // end Test_Customer
*****************************************************
/* * Test_SecurityHierarchy.java * * This test driver will allow for batch testing of all classes in the Security hierarachy. * * The test cases here are limited & generalized. Consider adding test cases to more fully * test the validation and exception handling in the associated classes. Testing for grading will include * different and additional test cases. * * (c) 2017, Terri Davis (updated 03/11/18) */ public class Test_SecurityHierarchy { /* * The following array holds the test cases. It may be enlarged as needed/desired. * * PLEASE NOTE: The first character in each String identifies which type of object is to be * instantiated. "M" = MutualFund; "S" = Stock. */ public static void main(String[] args) { String[] dataArray = { "S,1111111,19000101,0.0,0.0,SYMBOL,MARKET,false,0,0.0", // Stock test case template "M,1111111,19000101,0.0,0.0,SYMBOL,TYPE,0.0,P,false" // MutualFund test case template }; /* * The enhanced for loop will take each String in the above array, determine which type of object is to be * instantiated, and call the appropriate method based on that information. */ for(String candidate: dataArray) { String[] parts = candidate.split(","); // 'parse' the String into its constituent data items if(parts[0].equals("M")) // check the first data item for object type buildMutualFund(parts); else buildStock(parts); } // end for loop } // end main /* * If the String in the array contained data to create a MutualFund; execute this method. * * The individual data items will be extracted and converted (if necessary). The class constructor is called. * IF an exception is thrown, it is caught and a VERBOSE message is displayed to the errror output. * ELSE, the toString method of the newly instantiated object is output to System.out. */ private static void buildMutualFund(String[] parts) { MutualFund nextSecure; try { nextSecure = new MutualFund(// Security items parts[1], Integer.parseInt( parts[2] ), Double.parseDouble( parts[3] ), Double.parseDouble( parts[4] ), parts[ 5 ], // MututalFund items parts[ 6 ], Double.parseDouble(parts[7]), parts[8].charAt(0), Boolean.parseBoolean(parts[9])); System.out.printf("%s%n", nextSecure.toString( )); } // end try catch(SecurityException secErr) { System.err.printf("%s thrown%n%s%n", secErr.getClass( ).getName( ), secErr.getMessage( )); } // end catch SecurityException } // end buildMutualFund /* * If the String in the array contained data to create a Stock; execute this method. * * The individual data items will be extracted and converted (if necessary). The class constructor is called. * IF an exception is thrown, it is caught and a VERBOSE message is displayed to the errror output. * ELSE, the toString method of the newly instantiated object is output to System.out. */ private static void buildStock(String[] parts) { Stock nextSecure; try { nextSecure = new Stock(// Security items parts[1], Integer.parseInt(parts[2]), Double.parseDouble(parts[3]), Double.parseDouble(parts[4]), parts[5], // Stock items parts[6], Boolean.parseBoolean(parts[7]), Integer.parseInt(parts[8]), Double.parseDouble(parts[9])); System.out.printf( "%s%n", nextSecure.toString( )); } // end try catch(SecurityException secErr) { System.err.printf("%s thrown%n%s%n", secErr.getClass( ).getName( ), secErr.getMessage( )); } // end catch SecurityException } // end buildStock } // end Test_SecurityHierarchyready to do validation of the data items that are given as instance values for our objects. A variety of validation tests will be required, depending on the data type of the instance variable involved. Unacceptable data values will trigger exceptions in the code; exceptions will be instantiated to include a clear description of the issue and available information to help in locating or debugging the problem. Those exceptions must then be 'thrown' and passed up the call stack to the controlling process for proper handling. Startup Materials The following have been provided to you: .These instructions UML Class Diagrams for: o Customer (modified) o Security (modified) o MutualFund (modified) o Stock (modified) o CustomerException o SecurityException o Note that validation requirements appear in bold face in the UML Class Diagrams A test driver for testing updates to the Customer class: Test_Customer.java. NOTE: You will provide test cases used in the test driver. A template test case is included o .A test driver for use in testing your code: Test_SecurityHierarchy.java. NOTE: You will provide test cases used in the test driver. A template test case is included o Sample expected output results from both test drivers
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started