“Class” task… ho-ho

Object orientation task

This task is designed to guide you through some of the basics of object-oriented programming (OOP). It will also consolidate your knowledge of Java syntax and your general knowledge of programming. Because of the disparity in experience between members of the class, the task begins relatively easy, but gets much harder thereafter. If you do not understand some of the later tasks, do not worry! They are only there to keep the propellerheads occupied. I estimate that this task will keep two-thirds of the class busy, which will give me extra time to focus on those who need more help.

Student Database

Create a new project called StudentBase. Underneath the StudentBase class, write a Student class. Your Student should have a name, a height (in metres), and should be able to introduce themselves by saying “Hello. My name is [name] and I am [height] metres tall.” Use the template below to get you started.

package studentbase;

public class StudentBase {

    public static void main(String[] args) {
       StudentBase app = new StudentBase();

    void go(){
        // This is now your main routine

// This is where you define your Student class
class Student{
    // Add variables, constructors and methods in here


Further tasks:

  • Define a constructor for your Student that allows you to set the name and height when the Student object is created.
  • Give your student an array of 10 ints, called grades. In the constructor, populate the array with 10 random numbers from 60 to 99.
  • In your main routine, define an array of 20 students and print all of their grades in a table.
  • In your StudentDemo class, define a method that accepts an int grade and returns a String grade of A, B, C, D, or F.
  • Adapt your main routine so that it prints out their letter grades as well and calculates an average grade.
  • Add the following functionality:
    • Allow users to enter student data manually (try to make it easy for the user)
    • Save student records to file when the app closes and reload them when the app starts.
    • Allow users to sort the Students on name or height (there are standard sorting algorithms on the wall)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s