irmantas_radavicius

Sandbox.java

Mar 27th, 2022 (edited)
636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4.  
  5. public class Sandbox {  
  6.    
  7.     public static void main(String args[]) {       
  8.         try {
  9.             File storage = new File("store.txt");
  10.             File purse = new File("purse.txt");        
  11.            
  12.             Double[] coins = { 0.10, 0.2, 0.5, 1.0, 2.0 };
  13.             ArrayList<Double> coinsList = new ArrayList<Double>();
  14.             Collections.addAll(coinsList, coins);
  15.                                
  16.             Application app = new Application(storage, purse, coinsList);
  17.             Scanner sc = new Scanner(System.in);
  18.             while(true){
  19.                 System.out.print("Enter command: ");
  20.                 try {
  21.                     app.execute(sc.nextLine());
  22.                    
  23.                 } catch(IndexOutOfBoundsException e){
  24.                     System.out.print("No such item! ");
  25.                 } catch(NumberFormatException e){
  26.                     System.out.print("Invalid parameter! ");
  27.                 } catch(Exception e){  
  28.                     System.out.print(e.getMessage() + "! ");
  29.                 }
  30.             }          
  31.            
  32.            
  33.         } catch(Exception e){
  34.             System.out.println(e); 
  35.             e.printStackTrace();           
  36.             System.out.println("Unexpected error, sorry!");
  37.         }          
  38.     }  
  39. }
  40.  
Add Comment
Please, Sign In to add comment