Perry Smith

Java Questions & Answers

Home / Java Q & A Page 2 / Java Q & A Archive Main Page

A Java Model of a Modular Course Scheme
 Wednesday, 28-Oct-98 04:52:30

      193.60.160.157 writes:

      I need help withe following problem, so please help!

      A Java Model of a Modular Course Scheme
      In this model we wish to create Java classes whcich will model a simlified relationship between staff, students, courses
      and modules. The information to be held has been cut down to a minimum so as not to confuse the issue.

      The Scenario
      A person is identified by name and also has information on gender and date of birth. A person may either be a member
      of staff or a student. A member of staff will have a room number and a set of modules which they teach. A student has
      a computer user-name and the course which they are studying.
      A course has a name and a set of modules which make up each year of the course. Each year of a course comprises 2
      modules.
      A module is identified by a module number; it also has a title and a member of staff respondible for it. The timetable for
      the module should also be available.
      We should be able to input the basic details of specific staff, students, courses and modules but without their
      relationships. Additional functionality should be provided to allocate a module to a member of staff , identify a module
      as being on a year of a course, and register a student for a course.
      In addition there should be facilities for displaying all modules, a course timetable and a member of staff’s timetable.

      The Java Model
      You should model this scnario with Java classes, these can be developed in the following steps :
      1. Identify the classes required and any class hierarchies involved.
      2. Define the classes in terms of the class/instance fields and methods required; the fields should have their accessibility
      & types specified as should the methods but at this stage the method bodies need not be complete.
      3. Complete the method bodies.
      4. Create an application to test out the model



      i97mk2@tay.ac.uk

Responses
Re: A Java Model of a Modular Course Scheme
 Friday, 30-Oct-98 19:56:49

      152.205.252.251 writes:

      class Parent {

      /* CONSTANTS
      */







      /* VARIABLES
      */


      protected boolean isMale; // a variable that can only be accessed by this class and
      // it's subclasses and will hold only 1 of two values
      // assuming there are no hermaphrodites or neutered
      // people

      protected MyDate mdBirth; // a variable that can only be accessed by this class
      // and it's subclasses and will hold a date ... it will be a
      // separate class for the benefit of the project's group..
      // they may not like the current implementation ... so it
      // it will be it's own class to make interchanging it easy




      /* CONSRUCTORS
      */

      public Person // default constructor
      (
      )
      {
      }




      /* ACCESSORS
      */

      protected boolean isMale // accesses the isMale variable and returns it without
      // modification
      (
      )
      {
      return (isMale);
      }

      protected boolean isFemale // accessed the gender status returning the logical
      // opposite of the current stored value
      (
      )
      {
      boolean isRet;

      try
      {
      isRet = !isMale;
      }
      catch (java.lang.NullPointerException excpNPE) // arghh! the most dreaded
      // one of all
      {
      // handle the problem here...... probably with a excpNPE.toString() and a
      // System.exit(0) for now .. but change that later....
      }
      return (isRet);
      }





      /* MODIFIERS
      */

      protected void setMaleStatus // modify the gender variable
      (
      boolean isMale; // the new status for the gender variable
      )
      {
      this.isMale = isMale;
      }



      protected void setDate // modify the birthday
      (
      int iMonth, // uhh.. the month, maybe? ..
      int iDay, // uhh..I'll let you guess ..give up yet..okay okay..it's the Day of month
      int iYear // yes .. you're right .. this one's the year .. good guess
      )
      {
      mdBirth = new MyDate(iMonth, iDay, iYear); // or something like that...
      }

      protected void setDate // modify the birthday with more specific info
      (
      int iMonth, // birthmonth
      int iDay, // day of month of birth
      int iYear, // birthyear
      int iHour, // hour of birth, if known ....
      int iMinute // some people keep track of the minute of birth ....
      )
      {
      mdBirth = new MyDate(iMonth, iDay, iYear, iHour, iMinute);
      }


      /* HELPER METHODS
      */






      } // end of class defintion



      import java.util.Date;

      class MyDate
      {

      /* CONSTANTS
      */




      /* VARIABLES
      */

      private Date; // the storage type for this particular MyDate class



      /* CONSTRUCTORS
      */

      public MyDate
      (
      // place the appropriate variables here .. day month year ... etc
      )
      {
      // set the Date
      }





      /* ACCESSORS
      */

      public Date getDate
      (
      )
      {
      Date dateRet;

      // do stuff here to return the date information in the form of a java.util.Date object
      return (dateRet);
      }





      /* MODIFIERS
      */

      public void setDate
      (
      // place appropriate parameters here
      )
      {
      // do stuff to set the date here ...
      }


      }



      class Student extends Person
      {

      /* CONSTANTS
      */





      /* VARIABLES
      */

      private String strUserID; // identifier unique to each student
      private Course crsStudy; // the "course" the student is taking... in addition to
      // frequenting frat parties and testing various ethanols
      // it is rumored that some universities make you take
      // classes





      /* CONSTRUCTORS
      */

      public Student // default constructor
      (
      // this might be where it'd be good to put name and course parameters
      )
      {
      // do something useful here .. like setting the instance variables to the parameter
      // values
      }






      /* ACCESSORS
      */

      public String getUserID // access the UserID string and return it's unmdified value
      (
      )
      {
      return (strUserID);
      }



      public Course getCourse // access the course for this student object and return its
      // unmodified value
      (
      )
      {
      return (crsStudy);
      }

      public String toString // make all this information pretty
      (
      )
      {
      String strRet;
      // do stuff here..this one has many forms..shouldn't be that hard though since the
      // Course class will have it's own toString which will in turn call the Module
      // toString's ..
      return (strRet);
      }



      /* MODIFIERS
      */

      public void setUserID // modify the User ID string with the unmodofied value
      // of the parameter
      (
      String strNewName
      )
      {
      this.strUserID = strNewName;
      }



      public void setCourse // modify the course value with the unmodified value of the
      // parameter
      (
      Course crsNewCourse
      )
      {
      this.crsStudy = crsNewCourse;
      }


      /* HELPER METHODS
      */

      // might need some of these later on ... but I don't think so


      } // end of Student definition



      import java.util.Vector;

      class Staff extends Person
      {

      /* CONSTANTS
      */





      /* VARIABLES
      */

      private String strRmNum; // identifier unique to each staff member
      private Vector vecModules; // the modules that the staff member "teaches" .yes..it
      // may be that there is a professor that has taken it
      // upon himself to do the teaching ... but I doubt it ... so
      // this must be part of that effort to cut down on clutter
      // with this project so that there won't be a
      // GradStdntTchngAsst class needed




      /* CONSTRUCTORS
      */

      public Staff // default constructor
      (
      // this might be where it'd be good to put rm num and Vector parameters
      )
      {
      // do something useful here .. like setting the instance variables to the parameter
      // values
      }






      /* ACCESSORS
      */

      public String getRmNum // access the rm num string and return it's unmodified
      // value
      (
      )
      {
      return (this.strRmNum);
      }



      public Vector getModules // access the module list for this staff object and return
      // its unmodified value
      (
      )
      {
      return (this.vecModules);
      }



      public String toString // make all this information pretty
      (
      )
      {
      // many possibilities with this. it shouldn't be that hard though since the modules
      // will each have their own toString's..all that has to be done is to create a loop
      // to go through them ... probably using java.util.Vector.size() as one of the
      // loop control parameters of a for loop
      }




      /* MODIFIERS
      */

      public void setRmNum // modify the rm num string with the unmodified value
      // of the parameter
      (
      String strNewRmNum
      )
      {
      this.strRmNum = strNewRmNum;
      }



      public void setModules // modify the list of modules with the unmodified value of
      // the parameter
      (
      Vector vecNewModules // the new set of modules "taught" by this professor
      )
      {
      this.vecModules = vecNewModules;
      }


      /* HELPER METHODS
      */

      // might need some of these later on ... but I don't think so


      } // end of Staff definition



      class Course
      {

      /* CONSTANTS
      */

      private static final int NUMmODULESpERyEAR = 2; // who knows .. might switch
      // to quarters so they can
      // keep us longer and get
      // more money



      /* VARIABLES
      */

      private String strCrsName; // this unique identifier will probably be some
      // confounding alphanumeric combination developed to
      // aid freshmen (and inebriated seniors) in getting lost
      private Module mdulArray = new Module[NUMmODULESpERyEAR]; // the array
      // which
      // contains
      // the modules
      // will dominate
      // some poor
      // guy's life





      /* COSTRUCTORS
      */

      public Course // default constructor
      (
      // might want some parameters here to fill in the instance variables with
      )
      {
      // probably a good idea to fill in the instance variables here ...
      }







      /* ACCESSORS
      */

      public String getCourseName // access the course name and return it's
      // unmodified value
      (
      )
      {
      return (strCrsName);
      }


      public Module[] getModules // access the module array and return it's
      // unmodified value
      (
      )
      {
      return (strCrsName);
      }


      public String toString // make all this information nice and pretty
      (
      )
      {
      // do stuff here to order the information ... probably want a for loop with
      // java.lang.reflect.Array.getLength(mdulArray) as a loop control variable
      }





      /* MODIFIERS
      */

      public void setCourseName // modify the course name string
      (
      String strNewName
      )
      {
      this.strCrsName = strNewName;
      }


      public void setModuleArray // modify the module array
      (
      Module[] mdulNew
      )
      {
      this.mdulArray = mdulNew;
      }



      }




      // this leaves only the Module class and probably the drivers which wil store all of
      // the modules in a Vector or something. The drivers will also be providing the
      // functionality of taking user input and storing it in the right areas......


      MikeD

Home / Java Q & A Page 2 / Java Q & A Archive Main Page