Introduction to Computer Science II for majors by James Tam

Return to the course web page

CPSC 233: Assignment 2

Due February 3 at 4 PM

New Concepts to be applied for the assignment:

  1. Writing an Object-Oriented program in Java

Requirements:

Similar to the previous assignment: aside from the 'main' method you are not to write static methods for this assignment. (If you don't know what I'm referring to by static methods, I will be discussing this topic later in the course). Unlike the previous assignment you need to write multiple non-static methods for this assignment. (Unlike the previous assignment don't write all your functionality all in one method).

Okay:

public class Zodiac

     public void startZodiac ()
     {


     }

}

Not Okay:

public class Driver
{
     public static boolean isDayValid ()
     {


     }

}

The requirements for this assignment are identical to the ones for Assignment 1 except that you must now employ two classes:  1) A "Driver" class (that contains the 'main' method)  2) Another class, "Zodiac", that implements the features described in the previous assignment.  In Assignment 1 it was likely that your main method contained all of your program code.  For the second assignment it is likely that your main method will now just instantiate an instance of class Zodiac and perhaps include a method call or two to an instance of class Zodiac:

public class Driver
{
     public static void main (String [] args)
     {
          Zodiac aZodiac = new Zodiac();
          aZodiac.startZodiac();
     }
}
 

With this assignment most or all the calls to the different methods of class Zodiac are contained in the "startZodiac" method of class Zodiac.

public class Zodiac
{
     public final int JANUARY = 1;
     public final int FEBRUARY = 2;
          :         :         :
 
     private int month;
     private int day;
     private Scanner in;
     public Zodiac ()
     {
          :       :
     }
    // etc.
    public void startZodiac ()
    {
           // It will contain the calls to the methods that will get the day and month of birth. Also it will call the method to determine the zodiac sign.
    }
}

Constants that you should include in the definition of class Zodiac.

     JANUARY = 1;
     FEBRUARY = 2;
     MARCH = 3;
     APRIL = 4;
     MAY = 5;
     JUNE = 6;
     JULY = 7;
     AUGUST = 8;
     SEPTEMBER = 9;
     OCTOBER = 10;
     NOVEMBER = 11;
     DECEMBER = 12;
     MIN_DAY = 1;
     MAX_DAY = 31;
     MIN_MONTH = 1;
     MAX_MONTH = 12;
     DEFAULT = -1; // The exact default value assigned may vary but it should be a valid that is obviously invalid for the day and the month.

 

Variable attributes of class Zodiac

   month;
   day;
   A Scanner variable // Alternatively it can be a local variable

 

Methods of class Zodiac that must be implemented for this assignment

Method name

Return Type

Methods of class Zodiac called by this method

Description

Zodiac constructor None None Initialize the month and day attributes to default starting values. If the instance of class Scanner is an attribute of Zodiac then it should be instantiated in the constructor.

Introduction

void

 

Provides a brief overview of what the program does (user instructions).

determineSign

void

None

The month and day of birth attributes have already been entered by the user and validated by other methods before this method has been called. This method displays an appropriate message regarding the astrological sign based on the month and day of birth.

isDayValid boolean None Returns a true or false value depending upon the day of birth.
isMonthValid boolean None Returns a true or false value depending upon the birth month.
promptDay void None Displays an appropriate prompting message and gets the day of birth from the user (value is stored in the 'day' attribute).
promptMonth void None Displays an appropriate prompting message and gets the birth month from the user (value is stored in the 'month' attribute).
startZodiac void promptMonth(),

promptDay(),

isMonthValid(),

isDayValid(),

determineSign()

The starting point for this class and where most of the functionality gets invoked. However there should be very little code in this method, most of the code here will consists of calls to the other methods.

 

Testing

For this assignment you are to write at least two test Drivers that evaluate the correctness of a part of your program: (1) one driver will test the correctness of one your branches (2) another driver will test one of your loops. You should include information about your tests in a text file called README. That file should indicate what part of your program is being tested (which loop or branch), what are the conditions being tested (e.g., obvious false case for a branch) and the data used for each test condition (e.g., x = -123). Make sure you submit the test drivers and the README file along with your assignment code. The TA's will go over examples of test drivers in tutorial during the week of Jan 29 - Feb 4 so that's where/when you can get detailed information about how to do this in your assignment.

 

Submitting your work:

  1. Assignments (source code/'dot-java' files) must be electronically submitted according to [the assignment submission requirements].
  2. As a reminder, you are not allowed to work in groups for this class. Copying the work of another student will be regarded as academic misconduct (cheating).  For additional details about what is and is not okay for this class please refer to the following [link].
  3. Before you submit your assignment to help make sure that you haven't missed anything here is a [checklist] of items to be used in marking.

External libraries that can be used

  1. Libraries that allow for text-based (console) input and output.