Buggy code:
public class PA1 { private static final String INPUT_FILE_NAME = "pa1input2.txt" ; private static final String OUT_FILE_NAME = "pa1output.txt" ; public static void main ( String [ ] args ) { } static abstract class Trans { int serial ; String item ; int q ; int price ; public Trans ( int serial , String item , int q , int price ) { } abstract boolean isIn ( ) { } int getSerial ( ) { } int getQ ( ) { } int getPrice ( ) { } public String getItem ( ) { } @ Override public String toString ( ) { } } static class In extends PA1 . Trans { public In ( int serial , String item , int q , int price ) { } @ Override public boolean isIn ( ) { } @ Override public String toString ( ) { } } static class Out extends PA1 . Trans { public Out ( int serial , String item , int q , int price ) { } @ Override public boolean isIn ( ) { } @ Override public String toString ( ) { } } static ArrayList < PA1 . Trans > transactions = new ArrayList < PA1 . Trans > ( ) ; static void readFromFile ( ) { } static void basisAndGain ( ) { int total = 0 ; ArrayList < PA1 . Trans > current = new ArrayList < PA1 . Trans > ( ) ; ArrayList < PA1 . CostBasisAndGain > costBasisAndGainArrayList = new ArrayList < PA1 . CostBasisAndGain > ( ) ; for ( int i = 0 ; i < ( PA1 . transactions . size ( ) ) ; i ++ ) { PA1 . Trans trans = PA1 . transactions . get ( i ) ; if ( trans . isIn ( ) ) { current . add ( trans ) ; total += trans . getQ ( ) ; } else { int outQuantity = trans . getQ ( ) ; if ( outQuantity > total ) { System . out . println ( "error!!!" ) ; } else { int p = 0 ; int costBasis = 0 ; int sumOut = 0 ; for ( int j = 0 ; j < i ; j ++ ) { PA1 . Trans t1 = PA1 . transactions . get ( j ) ; if ( t1 . isIn ( ) ) { costBasis += ( t1 . getQ ( ) ) * ( t1 . getPrice ( ) ) ; } else { sumOut += ( t1 . getQ ( ) ) * ( t1 . getPrice ( ) ) ; } } sumOut += outQuantity * ( trans . getPrice ( ) ) ; total -= outQuantity ; PA1 . CostBasisAndGain costBasisAndGain = new PA1 . CostBasisAndGain ( trans . getSerial ( ) , trans . getItem ( ) , trans . getQ ( ) , costBasis , ( sumOut - costBasis ) ) ; costBasisAndGainArrayList . add ( costBasisAndGain ) ; if ( total == 0 ) { current . clear ( ) ; } else { for ( int j = 0 ; j < ( current . size ( ) ) ; j ++ ) { PA1 . Trans c = current . get ( j ) ; if ( outQuantity >= ( c . getQ ( ) ) ) { outQuantity -= c . getQ ( ) ; } else { p = j ; break ; } } for ( int j = 0 ; j < p ; j ++ ) { current . remove ( 0 ) ; } PA1 . Trans transp = current . get ( 0 ) ; current . remove ( 0 ) ; <START_BUG> current . add ( new PA1 . In ( transp . getSerial ( ) , transp . getItem ( ) , ( ( trans . getQ ( ) ) - outQuantity ) , transp . getPrice ( ) ) ) ; <END_BUG> } } System . out . println ( "Table<seq2seq4repair_space>1:<seq2seq4repair_space>Current<seq2seq4repair_space>Inventory" ) ; PA1 . printList ( current ) ; System . out . println ( "Table<seq2seq4repair_space>2:<seq2seq4repair_space>Cost<seq2seq4repair_space>Basis<seq2seq4repair_space>and<seq2seq4repair_space>Gains" ) ; PA1 . printList ( costBasisAndGainArrayList ) ; } } } static class CostBasisAndGain { int serial ; String item ; int quantity ; int costBasis ; int gains ; public CostBasisAndGain ( int serial , String item , int quantity , int costBasis , int gains ) { } @ Override public String toString ( ) { } } static void output ( ) { } static void printList ( List < ? > list ) { } }

Fix:
current . add ( new PA1 . In ( transp . getSerial ( ) , transp . getItem ( ) , ( ( transp . getQ ( ) ) - outQuantity ) , transp . getPrice ( ) ) ) ;