COMP 110 SS1 2012

In-class exercise: Methods

May 29, 2012

Description

The purpose of this exercise is to give you some practice in writing methods in classes. Given the code in StudentMain.java, write a class Student that has the necessary instance variables and methods for the code in StudentMain to run. Start off by first writing the UML diagram for the Student class (should look similar to notes from Friday). Then translate the UML diagram into code.

  • Give each variable a name and a data type
  • Name each method so that it matches its use in StudentMain, and give it the proper return type.
  • Write code for Student class - remember that this would go in a separate file called Student.java if you were writing it in Eclipse.
  • Make the method printData() use System.out.println() statements to output the student's name, class year and major.
  • The increaseYear method should check for the following:
  • After writing the code for the Student class, write down what StudentMain.java will output.
  • This exercise will not be graded. You are welcome to work in groups, but make sure you understand the concepts. Ask questions if you are having trouble.