Lecture 12 Objectives [Nov 13]prev next

MUSICAL COMPOSITION: Tchaikovsky Piano Concerto No.1 (premiered in Boston, Massachusetts on 25 Oct 1875)
 
Movement I (part 1)
12:16
Movement I (part2 )
12:09
Movement II
8:41
Movement III
8:31


At the end of today's class you should

HAVE READ:

KNOW:

BE ABLE TO:

DAILY QUESTION:


Sample Exam Question:

  1. A class has an instance method inst(), a static method stat(), and an instance variable data of type int.
  2. Given the Student class, which we have been using for our examples in lecture (as shown below), you have been asked to add a method that determines whether a particular student is a high school student (year of grad = 'HS') or a graduate student (year of grad = 'GS'). Write the method and be sure to include (a) documentation; (b) method signature; (c) method implementation. Be sure to clarify whether this is a static method or a non-static method.

     
    public class Student {

      /** Unique id. */
      String id;

      /** Student Name. */
      String name;

      /** Year of graduation. */
      String yearOfGrad;

      /** Major. */
      String major;
    }

     

  3. Given the Student class above, you have been asked to add a method that returns true if a given String represents an actual year of graduation (i.e., only contains digits '0' through '9') or returns false if the given String contains non-digit characters. Write the method and be sure to include (a) documentation; (b) method signature; (c) method implementation. Be sure to clarify whether this is a static method or a non-static method.
     
  4. Assume that you change the class definition for Student as below (just showing instance variables and static variables):

     
    public class Student {

      /** Unique id. */
      String id;

      /** Student Name. */
      String name;

      /** Year of graduation. */
      static String yearOfGrad;

      /** Major. */
      String major;

      ...
    }

    Assume you have a program that uses the Student class and it processes a set of students. Under what circumstances will the output of the program be unaffected by this change?
     

  5. Assume you have a class that contains a static variable count and an instance method meth(). If it is legal for meth() to update count provide one reason why this might be useful; if it is not legal for meth() to update count, explain the reason why it is illegal.