import java.io.*; import java.lang.*; //Testing tank by reading values to be added or removed from a data file public class testSamePercentage { public static void main(String[] argn) { try { String text; Tank t1 = new Tank(100.0); Tank t2 = new Tank(1000.0); DataInputStream inp = new DataInputStream(System.in); System.out.println("Enter File Name:"); String fname = inp.readLine(); InputStream ist = new FileInputStream(fname); DataInputStream istream = new DataInputStream(ist); text = istream.readLine(); while(text != null) { int am1 = Integer.parseInt(text.substring(0,1)); double am2 = (Double.valueOf(text.substring(2))).doubleValue(); if (am1 == 1) { t1.add(am2); System.out.println("t1 content after adding "+ am2 + " = "+ t1.content()); } else { t2.add(am2); System.out.println("t2 content after adding "+ am2 + " = "+ t2.content()); } text = istream.readLine(); } System.out.println("\n*** Its is "+Tank.samePercentage(t1,t2)+ " that t1 and t2 have the same fullness ratio "); } catch (FileNotFoundException e) { System.err.println("File does not exist"); return; } catch (IOException e) { System.err.println("Unsuccessful read"); return; } catch (IllegalArgumentException e) { System.err.println("Can't add/remove negative amounts"); return; } catch (Tank.TankOverFlowException e) { System.err.println("Tank overflow by "+e.overflow); return; } } }