Question: Need all this code changed to the point that it produces the same output. In Java coding, Thank You! import java.nio.file.Files; import java.nio.file.Paths; import java.io.ObjectInputStream;
Need all this code changed to the point that it produces the same output. In Java coding, Thank You!
import java.nio.file.Files;
import java.nio.file.Paths;
import java.io.ObjectInputStream;
import java.util.List;
import java.util.ListIterator;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.NoSuchElementException;
import java.io.IOException; //SuperClass
import java.io.EOFException; // End of file indicator
public class CustomerAccountReport { /*Place Declarations here*/ private static ObjectInputStream inSerial; private static ObjectInputStream inSerial_2; private static List customerColl = new ArrayList( ); private static List securityColl = new ArrayList( ); /*MAIN*/ public static void main( String[] args) { /*Next step contains the try block */ try { openFiles(); processReport(); closeFiles(); } // end try catch( IOException ioErr ) // for any error in the files { System.err.println( "Ending process." ); } // end catch catch( Exception err ) // All exceptions going through main { System.err.printf( "Serious error, Ending process. %s", err.getClass( ).getName( ) ); err.printStackTrace( ); } }// end main /* Open input files, find the files and define them. find deseralized objects */ public static void openFiles( ) throws IOException { try { inSerial = new ObjectInputStream( Files.newInputStream( Paths.get( "Customer.ser" ))); inSerial_2 = new ObjectInputStream( Files.newInputStream( Paths.get( "Security.ser" ))); } // end try block catch( IOException xcptn ) { System.err.println( "Error opening the input file, start terminating process." ); throw xcptn; //rethrowing exception }//end catch IOException } // end method openFile /*process report portion*/ public static void processReport( ) throws Exception { try { prepCustomerCollection( ); prepSecurityCollection( ); reportEquityPositions( ); } catch( Exception err ) { System.err.printf( "Serious error, Ending process. %s", err.getClass( ).getName( ) ); err.printStackTrace( ); } } // end method processRecords /*Close files * */ public static void closeFiles( ) throws IOException { try { if( inSerial != null && inSerial_2 != null ) inSerial.close(); inSerial_2.close(); }// end try block catch( IOException xcptn ) { System.err.println("Error closing input file, start terminating process." ); throw xcptn; }// end catch IOException } // end method closeFiles /** Customer selection is coming up next */ public static void prepCustomerCollection( ) throws ClassNotFoundException, IOException { /*Put things in order by the customer number*/ try { while( true ) { Customer customerObject = (Customer)inSerial.readObject( ); customerColl.add( customerObject ); Collections.sort( customerColl, new CustomerCustNumber() ); }//End while }//End try catch( EOFException eof ) { } catch( ClassNotFoundException xcptn ) { System.err.println( "Input file does not contain Customer object, start terminating." ); throw xcptn; }//end of ClassNotFoundException catch( IOException xcptn) { System.err.println( "Error DESERIALIZING objects, starting the terminating process."); throw xcptn; }//end of IOException } // end prepCustomerCollection /* security selection*/ public static void prepSecurityCollection( ) throws ClassNotFoundException, IOException { try { while( true ) { Security securityObject = (Security)inSerial_2.readObject( ); securityColl.add( securityObject ); //we are literally and physcialy reordering the collections Collections.sort( securityColl, new SecurityCustNumber() ); }//end of while loop }// end try block catch( EOFException eof ) { } catch( ClassNotFoundException xcptn ) { System.err.println( "Input file does not contain Security object, terminating." ); throw xcptn; }//end of ClassNotFoundException catch( IOException xcptn) { System.err.println( "Error DESERIALIZING objects, start terminating process."); throw xcptn; }//end of IOException } // end prepSecurityCollection /*Report the equity positions */ public static void reportEquityPositions( ) { /* * Declare an iterator for the security objects */ Iterator securityIterator = securityColl.iterator( ); Security equity = (Security)securityIterator.next(); String holdEquity = equity.getCustNumber(); findCustomer( holdEquity ); // Pass the custNumber value retrieved from the Security try { while( true ) { while( equity.getCustNumber( ).matches( holdEquity ) ) { // Output a line describing this Security System.out.printf( "\t%-10s %-5s carries a cost basis of %15s%n", equity.getClass( ).getName( ), equity.getSymbol( ), String.format( "$%,.2f", equity.calcCost( ) ) ); // Move to the next Security equity = (Security)securityIterator.next( ); } // end inside while // This is just an indication that we're done with this Customer's Security objects System.out.printf( "========================================================================%n%n" ); holdEquity = equity.getCustNumber( ); findCustomer( holdEquity ); } // end outside while } catch( NoSuchElementException endOfCollection ) { / System.out.printf( "%n%n\t\t\t * END OF EQUITY REPORT *%n" ); } // end catch NoSuchElementException } // end reportEquityPositions /*FIND CUSTOMER*/ public static void findCustomer( String findCust ) { Customer target; Customer found; try { /*CUSTOMER SEARCH */ target = new Customer( findCust, "000000000", "blank", "blank", 0, false, false ); /*locate object for customer, name it found*/ int location = Collections.binarySearch( customerColl, target, new CustomerCustNumber( ) ); found = customerColl.get(location); System.out.printf( "%n%-20s %-20s Customer %s, TIN %s%n", found.getFirst( ), found.getLast( ), found.getCustNumber( ), found.getTin( ) ); } catch( CustomerException err ) { System.err.printf( "Error searching the Customer list%n" ); } // end catch } } // end class CustomerAccountReport