CIS 161 Final Exam: Winter 2004

Problem One:  

Problem Two

What design principle is violated by the init() method in the following code? What would you do to fix it?

public class ExamFileA {
    
    private int value;
    private String name;
    
    public void init() {
        value = 1;
        name = "No name";
        
        System.out.println("System Version 0.01");
        System.out.println("CyberCoder 103X35");
        System.out.println(new java.util.Date());
    }
}

Problem Three

Given the classes and packages below, answer the questions following the graphic.

  1. In class Q what instance variables are available from class A?
     
  2. In class C what instance variables are available from class A?
     
  3. In class C what instance variables are available from class B?

Problem Four

Describe the difference between a checked and an unchecked exception.

Problem Five

Look up the Integer.parseInt() method in the API to find what type of exception it throws.

Given the code below, make the following changes:

public class IntInput {
    
    private static javax.swing.JOptionPane jop = 
                    new javax.swing.JOptionPane();
    
    private IntInput() {}
    
    public static int getInt() {
        int value;
        
        String input = jop.showInputDialog(null, "int?");
        value = Integer.parseInt(input);
        
        return value;
    }
}

Problem Six

Describe the concept of Coupling as discussed in your text. Give at least one example from the book.