CSE870 Homework 3

Java HACS System based on Design Patterns

Jianjun Hu, Yakub Sailanawala.

,

Usage:

To compile the code: javac HACS.java

To run the code: java HACS

Log in as instructor of cse870:

username: Betty

password: Cheng

Log in as instructor of hist900:

username: Indiana

password: Jones

Log in as student enrolled only in cse870:

username: Candy

password: Goran

Log in as student enrolled only in hist900:

username: Alice2

password: Jetsons

Log in as student enrolled both in cse870 and hist900:

username: Yolanda

password: Thompson

Course cse870 is a course of type 3 that has both Programming and Critiqueassignments.

Course hist900 is a course of type 1 that has only Critique assignments.

Description of the functionality of HACS

When you run the system, it will ask for the your username and password (first 2 fields of User.txt). Next it will ask you to select a course from a list. Once a course is selected, it cannot be changed throughout the session. Then you have to select an assignment. If the assignment list says NOASSIGNMENTS means there are no assignments posted at present. At this point an instructor can add an assignment clicking on the Assignment menu and choosing AddAssignment. When you add an assignment, it gets chosen automatically. The window has 3 menus System Assignment and Course The Course menu really does not do anything. It is only there to demonstrate the bridge pattern. It will change depending on the user (instructor/student) and course type. System has two options Logout and SelectAssignment. Assignment menu has different options depending on whether you logon as a student or instructor. Most of these will pop up a dialog box that is either message dialog box or one where you can enter information.

Following are options provided by the Assignment Menu for the instructor

  • AddAssignment: This will pop up a dialog box where you can enter AssignmentName, AssignmentType and DueDate.
  • GradeAssignment: This will give you a list of all the students, their solutions and their present grade (-1 indicated that grades have not been assigned). Then by selecting any student you can enter grades for her.
  • ReviewStudentSolution: This will give you a list of all the students, their solutions.
  • PrepareGradeSheet: This will let you view a list of all the students with their grades for this assignment
  • StudentAverageGrade: This option will let you view a list of all the students with their average grades. This average is computed over all the assignments for the selected course. This option was provided to demonstrate the Visitor Pattern
  • AssignmentAverageGrade: This option will give you the average grade for this assignment computed over all the students. This option was provided to demonstrate the Iterator Pattern

Following are options provided by the Assignment Menu for the student

SubmitSolution: submit a homework solution

ViewKey: see the reference solution provide by instructor

ViewGrade: view his/her grade of this assignment

Note: Before accessing any of the assignment based options make sure that you have chosen the correct assignment or else you can modify wrong information

Also included are the following data files:

Use.txt: information about all the users of HACS system

cse870Student.txt: list of all the students enrolled in cse870hist900Student.txt : list of all the students enrolled in hist900

To add another course the administrator will need to update User.txt file and add <coursename>Student.txt file.

Basic Organization:

The initial data is stored in 3 files.

1) User.txt: This file contains information about all the users of this system. These users are students as well as instructors of all the courses running on HACS. The format of the file is as follows

username password Firstname Lastname usertype PID course1 -course1type course2 course2type … coursen coursentype

  • Each user is assumed to have a different username.
  • Usertype is 1 if the user is a student and 2 if she is an instructor.
  • PID is a00000 for instructors.
  • course is the name of course this user has enrolled for or is teaching like cse870
  • In order to implement the bridge pattern we have 3 different course types.

1 corresponds to course with just critique or textual homework assignments

2 corresponds to one which has just programming assignments

3 corresponds to a course with both types of assignments

  • A user can be enrolled in more than one course

2) For each course that runs on HACS. There is a file containing the list of all the students enrolled for that course. This file is added by the administrator (us in this case). The file name will be <coursename>Student.txt e.g. for cse870 it will be cse870Student.txt. These files have the same format irrespective of the course type, which is: PID FirstName LastName.

Up until now all these files and the data there in is maintained by the administrator. The rest of the files and the data in them is automatically generated and maintained by HACS based on user response.

HACS maintains a list of all the assignments for each course in the file <coursename>Assignment.txt, for e.g. for cse870 we will have cse870Assignment.txt. This file is automatically generated when the instructor adds the first assignment. The format of this file is as: AssignName AssignType DueDate AnswerKey

  • AssignType: 1 – critique , 2 – programming
  • DueDate: mm-dd-yyyy
  • AnswerKey: name of the answer key

At this point the course object also generates and other file<coursename<hwname>.txt for e.g. for cse870 and assignment-name: Therac the file generated will be cse870Therac.txt. This file maintains the records of all the student’s solutions and their respective grades for this assignment.The format of this file is:

PID StudentFirstName StudentLastName SolutionName Grade

For this project we have assumed that all grades will be distributed in percentages. So the maximum grade for any assignment and for any course is 100. Also, all the grades are initialized to –1.

Classes:

Data processing class:

  • HACS: This is the main class
  • User: This class represents the user of HACS
  • CInstructor: This is derived from User and represents an instructor
  • CStudent: This is derived from User and represents a student
  • Course: This class represents a course (there can be different types of courses)
  • Homework: This class represents a homework assignment (there can be 2 types of homework assignments)
  • Solution: This class represents a solution of an assignment
  • LogWin: This class implements the login windoe and validated the user against the User.txt file. It also initializes the corresponding User object
Design Pattern related class

Implementation of Façade, Singleton and Factory method patterns

HACS:

the HACS system with simple uniform interface (login, load_optionmenu, ExecuteOption)

Implementation of Bridge pattern

User_UI: Abstract base class for user sensitive menus.

Student_UI: implementation class for student specific menus

Instructor_UI: implementation class for instructor specific menus

Course_Menu: Abstract base class for course sensitive menus.

Course_Programming_Menu

implementation class for courses (with programming assignment) specific menus

CourseCritique_Menu:

implementation class for courses (with critique assignments) specific menus

CourseCritProg_Menu:

implementation class for courses (with both critique and programmingassignments) specific menus

Implementation of Visitor Pattern

Student_Visitor: Abstract base class for student visiting class.

StudentVisitor_GetAverageGrade:

use this visitor to get the average grade of all assignments of a specific course

Implementation of Iterator pattern

UserIterator: Abstract base class for student iterator class.

UserIteratorList: implementation of sequence visiting of students.

UserInterface class: all kinds of dialogs.

  • SubmitSolutionDialog
  • SubmitFileDialog
  • SelectCourseDialog
  • ReviewSolutionDialog
  • InputGradeDialog
  • GradeReportDialog
  • GradeAssignmentDialog
  • AddAssignmentDialog

Class Diagram:

Description of the class relationships:

UserIteratorList is a subclass of UserIterator to implement sequential access to students of registered in a course;

StudentVisitor_GetAverageGrade is a subclass of student_visitor class to implement additional function for student user, that’s to get the average grade of a course. We don’t implement the studentVisitor_GetAllGrade yet. Only for illustration.

Course_Programming_Menu, CourseCritique_Menu, CourseCritProg_Menu are three subclasses of Course_Menu. They are used to implement course-dependent menus.

Instructor_UI and Student_UI are subclasses of User_UI for implementation of user dependent menus. Each User_UI has a instance of Course_Menu. These two menus will be combined together before display.

HACS class is the encapsulation of the whole system. Façade, singleton and factory patterns are used here. There is only one HACS instance in the application. It includes a current Selected course, a selected homework and a current user.

Each Homework has a instance of solution object. It is also related to a course.

Each course has one instructor and one or more students.

Cinstructor and CStudent are subclass of User class, which represents the only two participant in our current version.

Patterns used:

Bridge pattern:

Bridge pattern is used here to implement the course sensitive menus. According to the courses selected by the user, different course menus will be displayed. We also implement user specific menus using the same pattern technique.

Participants:

User_UI, Student_UI, Instructor_UI, Course_Menu, Course_Programming_Menu, CourseCritique_Menu, CourseCritProg_Menu

Class Diagram:

Advantages:

In this HACS, it is very convenient for instructor to specify different course menus for students by just inheriting a new class from course_Menu. This flexibility comes from bridge pattern.

Façade pattern:

Façade pattern is used to encapsulate the complexity of HACS subsystem. Straightforward interfaces are provided to access the functions of HACS.

Participants: HACS

Advantages: Information hiding enables easy reuse by other system developer to this subsystem functions.

Class diagram:

Factory Method

Factory method is implemented in Load_OptionMenu(int usertype, int courseType) of HACS class. Here different user_interface (menu) objects are constructed based on the user type and course type selected.

Participants: HACS

Advantage: we can display the menus adaptively based on the user type, implementing the context sensitive user interface.

Iterator

Iterator pattern is used here to visit students of a course. With different implementation iterator class, we can access different subset of all the students of a course.

Participants: UserIterator, UserIteratorList

Class Diagram:

Advantage: To dynamically implement different student subset visiting. We can dynamic change the behavior by just instantiating the visitor object with different concrete visitor class. For example, we can only visit male students or female student by implementing another GenderStudentVisitor.

Singleton

Singleton pattern is used to ensure that only one instance of HACS system object exists. The unique instance is always accessed by HACS: instance (). It is implemented with static data member of HACS class.

Participants: HACS

Advantage: since HACS accesses many data files, multiple instance of HACS objects may cause the file sharing conflicts or destroy file integrity caused by file sharing. Singleton pattern enables us to have unique HACS object in the whole system.

Visitor

Visitor pattern is an efficient way to provide additional functionality to an existing class. What we need to do is just inherit from Visitor base class Student_Visitor and implement the concrete functions. In HACS system, visitor enables us to add additional function to Cstudent class. In this implementation, we add the GetAverageGrade() function to the Cstudent class.

Participant: Student_Visitor,StudentVisitor_GetAverageGrade

Advantage: Dynamic binding of additional functionality to existing class enables flexible dynamic behavior of system. It also makes our HACS extensible to provide other specific functions which may be needed for further system extension.