1. File f = new File("MyData.txt");
    2. Scanner in = new Scanner(f);
    3. PrintWriter out = new PrintWriter(f);
  1. double sum = 0.0;
    while (in.hasNextDouble()) {
        double n = in.nextDouble();
        sum += n;
    }
    
    1. OK
    2. OK
    3. Error
    4. OK
  2. try {
        PrintWriter out = new PrintWriter(new File("MyOutput.txt"));
        out.println("This is my output file.");
        out.close();
    } catch (FileNotFoundException fnf) {
        System.err.println("Could not open file.");
    }
    
  3. public class Thingy implements Comparable<Thingy>
    {
        private int value;
    
        public Thingy(int v)
        {
            value = v;
        }
        public int getValue()
        {
            return value;
        }
    
        public int compareTo(Thingy that) {
            return this.value - that.value;
        }
    
    }
    
  4. public static void cheer(int n)
    
    {
    
        if (n < 0)
    
        {
            throw new IllegalArgumentException
            System.err.println("No negatives allowed");
    
            System.exit(1);
        
        }
    
        for (int i = 1; i <= n; i++)
    
        {
    
            System.out.println("Hip-");
    
        }
    
        System.out.println("Hooray!");
    
    }
    
  5. public interface Usable {
        public void showValues();
        public boolean hasZeroValue();
        public int getZeroLocation();
        public double solve(int zero);
    }
    
  6. d)
    c)
    b)
    a)