Digital Music Programming Mid-term Exam (Fujinaga, March 1998)

1. Answer the following questions (5 points each):

2. Create a class Rectangle. Use float variables to represent length and width, both of which defaults to 1 (15 points).

3. Find errors in the Java source code below. There are at least ten errors (10 points):

import java.awt.*; 
import java.awt.event.*;
public class Index extends Applet implements ActionListener 
{ 
  private TextArea input, output; 
  private Button b; 
  private int count; 

  public void init() 
  { 
    b = new Button( "Click here to enter text" ); 
    b.addActionListener( this ); 
    prompt = new Label( Enter some text: ); 
    input = new TextArea( 20, 20 ); 
    add( prompt ); 
    add( input ); 
    add( output ); 
  }
  public void paint( ActionEvent g ) 
  { 
    count = 0; 
    output.setText("");
    String alphabet[26] = "abcdefghijklmnopqrstuvwxyz";
    String s = input.getText().toLowerCase();
    for (i = 0; i < alphabet.length(); i++ ); 
      g.drawString(alphabet[i], 10, 10); 
    system.out.println(s);
}