import javax.swing.JOptionPane; import java.io.IOException; /** Questo programma chiede all'utente di inserire il nome di un file contenente descrizioni di monete. Un oggetto di tipo Purse viene riempito con le monete specificate nel file. In caso venga lanciata un'eccezione, l'utente puo' scegliere un altro file */ public class PurseTest { public static void main(String[] args) { boolean done = false; String filename = JOptionPane.showInputDialog("Enter file name"); while(!done) { try { Purse myPurse = new Purse(); myPurse.readFile(filename); System.out.println("total =" + myPurse.getTotal()); done = true; } catch(IOException exception) { System.out.println("Input/Output error" + exception); } catch(NumberFormatException exception) { // Elenco della catena di invocazioni di metodi che ha portato all'eccezione exception.printStackTrace(); } if(!done) filename = JOptionPane.showInputDialog("Try another file:"); if (filename == null) done = true; } System.exit(0); } }