? 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 15 - 1
Chapter 15
Case Study,
Class Roster Maintenance Program
2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 15 - 2
Chapter 15 Objectives
After you have read and studied this chapter,you
should be able to
Develop large programs incrementally using
multiple objects from object categories
controller,storage,application logic,and user
interface.
Develop large programs that are extensible and
modifiable by applying polymorphism and
inheritance effectively in program design.
Document how the methods in the classes are
related by using method call sequence
diagrams.
2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 15 - 3
Sample Program,Computing Course Grades
Problem Statement
Write a class roster maintenance program that will allow the user to
Create a new roster.
Open an existing roster (can open one roster at a time).
Save the current roster to a file.
Add and delete students from a roster.
Change the name of students.
Edit the test scores of students.
Display the name,test scores,and course grade of a single student or all
students in the roster.
The program maintains both graduate and undergraduate students,For each
student,we maintain his or her name,test scores,and final course grade,The
final course grade is computed by using the following formula (from Chapter 14):
Type of Student Grading Scheme
Undergraduate Pass if (test1+test2+test3)/3 >= 70
Graduate Pass if (test1+test2+test3)/3 >= 80
2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 15 - 4
Design Document - 1
Design Document,GradeRoster Program
Class Purpose
GradeRosterMain The main class of the program.
GradeRosterMainWindow
The top-level control object that manages other objects in the program,The class is a
subclass of MainWindow from javabook.
GradeRosterControl
An object that controls a GradeRosterobject,The object works under the control
of GradeRosterMainWindow,The object manages StudentNameDialog and
TestScoreDialog objects.
GradeRosterDisplay
An object responsible for displaying class rosters,The object works under the control
of GradeRosterMainWindow.
2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 15 - 5
Design Document - 2
Design Document,GradeRoster Program
Class Purpose
GradeRosterStorage An object for handling the file input and output operations,The object works under the control of GradeRosterMainWindow.
GradeRoster
An object that actually maintains the roster,The object works under the control of
GradeRosterControl.
Student
An abstract class that captures common behavior and data of both undergraduate
and graduate students.
2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 15 - 6
Design Document - 3
Design Document,GradeRoster Program
Class Purpose
GraduateStudent An object to model a graduate student.
UndergraduateStudent
An object to model an undergraduate student.
MessageBox
A javabook object to print out error messages and messages from temporary
output statements.
2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 15 - 7
Grade Roster Program,Object Diagram
GradeRosterMain
Graduate-
Student
Under-
graduate-
Student
GradeRosterGradeRoster-
Display
GradeRoster-
Storage
GradeRoster-
Control
GradeRoster-
MainWindow
2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 15 - 8
Development Steps
1,Start with the program skeleton,Define the GradeRosterMain and skeleton
GradeRosterMainWindow classes.
2,Implement the methods to create a new roster.
3,Implement the methods to add students to a roster.
4,Implement the methods to delete students from a roster.
5,Implement the methods to edit student information.
6,Implement the methods to edit test scores and compute the final course grades.
7,Implement the methods to display the student information of a single student or all
students.
8,Implement the methods to save a roster to a file and read a roster from a file.
9,Finalize and look for improvements.
2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 15 - 9
Step 1,Program Shell with Menus
Step 1
Objects To Do
GradeRoster-Main Implement the full class,The mainmethod creates an instance of
GradeRosterMainWindowand calls its setVisible method.
GradeRoster-MainWindow Implement the shell of the main class that includes menu choices and corresponding
methods for processing menu choices.
2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 15 - 10
Step 2,Create a New Roster
Step 2
Objects To Do
GradeRoster-MainWindow Implement the methodsnewRoster
createNewRostersetNewTitle
Modify the constructor as necessary.
Add a ResponseBoxcalled saveBoxas a new data member.
Define constants SAVE,NO_SAVE,and CANCEL.
GradeRoster-Control Implement the methods
<constructor>getCourseTitle
hasGradeRosternewGradeRoster
Add InputBoxas a new data member.
GradeRoster Implement the methods
<constructor>getTitle
2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 15 - 11
Step 3,Add Students
Step 3
Objects To Do
GradeRoster-MainWindow Implement the method
addNewStudent
GradeRoster-Control Implement the methods
addStudentaddGraduateStudent
addUndergraduateStudent
Modify the constructor as necessary.
GradeRoster Implement the methods
addStudentgetStudent
expandRoster
2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 15 - 12
Step 4,Delete Students
Step 4
Objects To Do
GradeRoster-MainWindow Implement the method
deleteStudent
GradeRoster-Control Implement the method
deleteStudent
GradeRoster Implement the methods
deleteStudentcompactRoster
2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 15 - 13
Step 5,Edit Student Names
Step 5
Objects To Do
GradeRoster-MainWindow Implement the method
editStudentName
GradeRoster-Control Implement the method
editStudentName
Modify the constructor and data member declaration as necessary.
StudenName-Dialog Define this class fully.
2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 15 - 14
Step 6,Edit Test Scores and Compute Grades
Step 6
Objects To Do
GradeRoster-MainWindow Implement the methods
editTestScorescomputeGrades
GradeRoster-Control Implement the methods
editTestScorescomputeGrades
Modify the constructor and data member declaration as necessary.
GradeRoster Implement the method
computeGrades
TestScore-Dialog Implement this class fully.
2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 15 - 15
Step 7,Display Student Information
Step 7
Objects To Do
GradeRoster-MainWindow Implement the methods
showAllStudentsshowOneStudent
Modify the constructor to crete and initialize an instance of GradeRosterDisplay.
GradeRoster-Control Implement the method
getRoster
GradeRoster-Display Implement the methods
displayAlldisplayOne
Modify the constructor and data member declaration as necessary.
Student Implement the method
getValues
GradeRoster Implement the method
getAllStudents
2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 15 - 16
Step 8,Storing Grade Rosters
Step 8
Objects To Do
GradeRoster-MainWindow Implement the methods
openRostersaveRoster
saveAsRoster
Modify the constructor to crete and initialize an instance of GradeRosterStorage.
GradeRoster-Control Implement the method
setGradeRoster
GradeRoster-Storage Implement the methods
savesaveAs
saveDataopen
loadData
Modify the constructor and data members.
2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 15 - 17
Step 9,Finalize and Improve
We review all classes for consistency and
completeness,Some of the questions we ask
ourselves while reviewing the classes are
1,Are the methods named logically and consistently over
the classes?
2,Are there any overburdened classes that handle too
many tasks?
3,Are the links between the classes clear and logical? Are
there too many links between the classes?
4,Have we considered all possible operations? Are there
any other operations we should support?
5,Is the program’s user interface logical and easy to use?
The End