Project 2 (Document Version : 1.0; Revised: February 15)
Assigned:
Wed,
Feb-16-2011
Due:
11:59
p.m, Friday, Feb-25-2011
1.
Objectives:
Write java programs with multiple classes.
Understand data abstraction.
Understand how to use interfaces.
2.
Setup:
Create
a directory named project2 under your cs180 directory. To do that,
issue the following commands from the terminal:
$
pwd
/home/yourlogin/cs180
$
mkdir project2
$
cd project2
Download file project2.jar and save it into project2 folder.
Download Student.java and save it into project2 folder
Goto Dr Java Menu, Edit -> Preferences -> Resource Location (First option under Categories) -> Extra Class Path -> Click Add. Select the project2.jar file in the menu and Apply.
3.
Project Description
You
have to create a java project that simulates a student attending
different classes in Purdue U. A student may be enrolled in different
classes/courses each with its own unique grading scheme. That is, for
a fictional Math 001 course, grade may be decided based on how you
perform on home-works and assignments, but for a CS 001 course, grade
may be decided based on your exam performance. You have to write java
classes that simulate this behavior.
A
good understanding of what interfaces are and how to create and use
them is required before you start implementing. You will be required
to write multiple classes that implement an interface.
In
the context of this project, the following attributes are defined as
below
Subject - “Math” or “CS” (Only these two values need to be supported)
Course# - A number like 177 , 180 or 240 (User can enter any integer value)
Course Name - Subject and course# together makes up the course name (eg: “Math 170” or “CS 180” or “Math 240”)
Course Title - A meaningful name for the course (eg: course “CS 180” may have title - “Object_Oriented_Programming”)
You should use the Scanner class to read all details as shown in the image below. (Everything in green font is user input) Note that the program prompted the user to enter details twice because user entered 2 in response to the question “How many classes are you taking this semester”. In general, if user enters n , your program should ask for these details n times.
All values (attendance percentage, home-work score and exam score) should be less than 100. Just to make life easier, you don’t have to handle course titles with blank spaces in them (like “Operating System”) You can expect the user to always enter a single word without spaces (like Operating_System)
Output
The final goal is to print a transcript that looks like the picture below.
4.
Steps to solve the problem
The
jar file project2.jar contains multiple classes. You will be using
the University
class and Course
interface. Familiarize yourself with
the methods in them before you proceed. There is also an IStudent
interface which is already implemented by the Student class. Note
that some methods in University class takes IStudent interface as a
parameter.
Method Summary – University class (Refer to Javadoc link for details)
void markAttendance(cs.IStudent student, cs.Course course, int noOfDays)
Updates student registration information and marks that student attended course for noOfDays
void printTranscript(cs.IStudent student)
Looks at all previous information of a student and prints the transcript
void register(cs.IStudent student, cs.Course course)
Registers student for the course specified.
void updateExamScore(cs.IStudent student, cs.Course course, int examScore)
Updates student registration information, setting exam score to the value specified in examScore parameter
void updateHwScore(cs.IStudent student, cs.Course course, int hwScore)
Updates student registration information, setting homework score to the specified hwScore parameter
Method Summary – Course Interface (Refer to Javadoc link for details)
java.lang.String calculateGrade(int attendance, int homeWorkScore, int examScore)
Calculates grade based on attendance, hwScore and examScore.
java.lang.String getCourseName()
Returns courseName.
java.lang.String getCourseNo()
Returns Course#
java.lang.String getCourseTitle()
Returns Course Title
java.lang.String getSubject()
Returns subject
Step 4.1: Creating MathCourse class
Create
a new class called MathCourse
that
implements the Course
interface.
This class should be in your project2 folder. MathCourse
should
implement all methods specified in 'Course'
interface.
Remember that you need to import
cs.Course
before
you can start using Course
interface.
Design your MathCourse class in such a way that it has attributes to
store all the information required for the methods in it.
For
example, if getCourseName() is called on an object representing
“Class 1 Details” in Figure 1, it
should return “Math 101”. See Step
4.3 for more details. Of course, if getSubject() method is called
on the same object, it should return “Math”.
calculateGrade(....)
for Math Courses
For all Math subjects (irrespective of course#), final grade is determined as below. First calculate final_score using the following breakup
Attendance |
20.00% |
Home-works |
40.00% |
Exam |
40.00% |
Then calculate final grade as :
if final_score >= 80 |
Grade 'A' |
if final score >= 60 and < 80 |
Grade 'B' |
if final score <60 |
Grade 'C' |
eg: if attendance = 70, homework score = 60 and exam score = 70, then
final_score = 70 * 20% + 60 * 40% + 70 * 40% = 66, So, grade will be 'B'
Your calculateGrade(int attendance, int homeWorkScore, int examScore) method in MathCourse class should return a letter grade using the algorithm above.
Step
4.2: Creating
CSCourse class
Create
a new class called CSCourse
that
implements Course
interface.
This class should be saved in your project2 folder. CSCourse
should
implement all methods specified in Course
interface.
Again, design your CSCourse
class
in such a way that it can store all attributes required for the
methods in it. Just like MathCourse,
CSCourse
should
return the correct courseTitle, subject etc, when appropriate methods
are called.
calculateGrade(....) for CS Courses
For all CS subjects (irrespective of course#), final grade is determined as below. First calculate final_score using the following breakup:
Attendance |
10.00% |
Home-works |
60.00% |
Exam |
30.00% |
Calculate final grade as :
if final_score >= 75 |
Grade 'A' |
if final score >= 65 and < 75 |
Grade 'B' |
if final score >= 55 and < 65 |
Grade 'C' |
if final score < 55 |
Grade 'D' |
eg: if attendance = 70, homework score = 60 and exam score = 70, then
final_score = 70 * 10% + 60 * 60% + 70 * 30% = 64, So, grade will be 'C'
Note that even if attendance, homework score and exam score is same for a CS course and Math Course, the final score and letter grade could be different. Also note that there is an extra grade level (D) for CS.
Step 4.3. Putting it all together (Student.java).
At this point you should have two classes MathCourse and CSCourse with all methods defined and compiled without errors. Rest of your code should go in the Student.java file provided with this project. This is the class that will be executed to test your project.
You have to write a method that reads user input as shown in Figure 1. Refer back to the UserInput section.
Based on user input you have to create either a MathCourse Object or a CSCourse Object. If user enters “Math” as the subject, you should create a MathCourse Object. If user enters “CS” as subject, you should create a CSCourse Object. If user enters anything other than “Math” or “CS”, display an error.
Populate the object you created in step 2 above with remaining details like subject, course# etc. (You should've designed your classes in such a way that this is possible) Once your object is built, calling methods like getCourseTitle() or getCourse() should return appropriate details.
Call the register method of University class to register the student with that course. (Remember you are already working with the student object)
After registration, call the markAttendance, updateExamScore, and updateHwScore method of University class with the value user entered for this .
Finally, when all course information is successfully recorded with the University object, call the printTranscript() method to print the transcript. If your implementation is correct, you should get a transcript as shown in in Figure 2.
5. Grading Rubric *
Coding Standards & Correct Turnin** |
10 |
No Compilation Errors |
15 |
User Input |
25 |
MathCourse class implementation |
10 |
CSCourse class implementation |
10 |
Correct Output |
30 |
* The grader may look at your program in its entirety rather than individual modules to reasonably award points.
** Points may be deducted for turning in using email. Also ensure that your turnin folder does NOT contain .class files, metadata files (if you are using eclipse or other editors) or jar files.
6. Turn in instructions
Change your current folder to your cs180 folder and run the turnin command:
$ pwd
/home/yourlogin/cs180/project2
(Make sure your project2 folder contains only Student.java, MathCourse.java and CSCourse.java. Remove any class files, jar files or META folders before you submit)
$ cd ..
$pwd
/home/yourlogin/cs180
$ turnin -v -c cs180=XXX -p project2 project2
*XXX is your recitation section number. Check here if you don’t remember.