CSC 211 -- Java Programming I

Practice Midterm D

Show your answers and other work in your bluebooks. Do only 4 out of 5 problems.

  1. If you choose this question, answer both parts.

    1. Explain what the words public, static, and void mean in the header of the main method.

    2. Many people think that Java is hard because it uses classes and objects so early. Do you agree or disagree?
      Give some important examples of classes that you have already used in Java.

  2. Construct the variable trace and predict the output of the following Java program:

    public class Main
    {
        public static void main(String[] args)
        {
           int x = 60, y = 100, z = 0;
           String a = "";

           while(x > 0 && y > 0)
           {
              if (x >= y)
                 System.out.println(x + a + y);
              else
                 System.out.println(y + a + x);
              x /= 3;
              y /= 4;
              z++;
              a = z + "-" + a + z;
           }
        }

    }

  3. Write a complete Java main method that will read one string from the keyboard and print out "Yes" if the string begins or ends with lower case e, and "No" otherwise.

  4. Write a complete Java main method that will read a list of hours worked, terminated by a negative value. Each list input indicates how many hours an employee worked that week. Hours over 40 are overtime hours for that employee. After the list is terminated, print out these summaries:
    1. The number of employees that worked more than 40 hours that week,
    2. The total number of overtime hours.

  5. Write an Applet paint method that draws the following picture. The size of the applet is 150 x 150.