Assignment 1 (due 7 Feb)


In this assigment you will write an object oriented program using Java that will calculate your final grade for this class.  

To be handed in:  a diskette labeled with your name, containing your .jpr project file and your source (src) directory containing your .java files.  Also include a printout of your .java files.

The project will consist of the following classes:

GradeComponent

String componentName

the name of the grade component ( e.g.: "final", "test1", "program1")

int totalPoints

the total number of points possible for this grade component

int earnedPoints

the number of points earned for this grade component

GradeComponent(String componentName, int totalPoints)

constructs a new GradeComponent object with the specified name and total points; the earnedPoints are initialized to 0.

 

Sample invocation: 

GradeComponent finalExam = new GradeComponent("final", 400);

void setEarnedPoints(int earned)

to set the number of points earned for this grade component

int getEarnedPoints()

returns the number of points earned for this grade component

int getTotalPoints()

returns the total number of points possible for this grade component


Student

String studentName

the name of the student

String studentId

student identifier (unique)

Student(String studentName, String studentId)

constructs a new Student object with the specified name and id

 

Sample invocation: 

Student aStudent = new Student("Matthew Smith", "999-99-9999");

String getStudentName()

            returns the name of the student

String getStudentId()

            returns the student id


StudentGrade extends JApplet   // your user interface Is-a JApplet!

Student aStudent

a student object

Vector gradeComponents

a collection of student grades

 

Notice how your StudentGrade JApplet uses (contains) objects instantiated from the two previous classes.

int finalGrade()

computes and returns the numeric value of the student's final grade -- a rounded integer value, normalized from 0 to 100, that represents the student's percentage of  total earned points out of the total possible points across all grade components

char letterGrade()

computes and returns the student's letter grade (e.g.:'A' ,'B', and so on…)


 

(!) Note: All constructors and all instance methods should be public, and all attributes should be private (or protected).

 

The GUI (Graphical User Interface) will have to look like this:

This interface permits the user to enter their student name and ID (you can make up an ID), then press the <Add Student> button to instantiate a student object from class Student.  Pressing the <Add Student> button should also use a System.out.println() statement -- and the getStudentName() and getStudentId() methods -- to display the student name and id.

The next 3 fields and the <Add Grade Component> button permit the user to input the grade components for this course as follows:

 

Component name

Total points

Earned points

Final exam

400

make up a grade between 0 and 400

Test 1

150

make up a grade between 0 and 150

Test 2

150

make up a grade between 0 and 150

Program 1

75

make up a grade between 0 and 75

Program 2

75

make up a grade between 0 and 75

Program 3

75

make up a grade between 0 and 75

Program 4

75

make up a grade between 0 and 75

Specifically, pressing the <Add Grade Component> button has the following effect: it instantiates a grade component object from class GradeComponent (initialized from the component name and total points fields), adds the grade component object to the gradeComponents vector, and sets the grade component object's earned points to the value from the earned points field.

After entering all 7 grade components, pressing the <Final Grade> button will display the final grade, formatted as follows:  95(A) or 78(C).  This requires some output formatting, but it should be obvious which methods you will need to use from the above classes.  Pressing the <Final Grade> button should also use System.out.println() statements to display detailed grade information, as a way to verify the student's final grade.  Nothing fancy, just one line for each grade component.

To calculate the numeric final grade, after summing across the vector of grade components, the following Java code may be helpful:

   (int) Math.round( totPointsEarned * 100.0d / totPointsPossible )
   // Notice the use of 110.0d to force double arithmetic.
   // The cast is to lower this from a long to an int.

Note:  using System.out.println() is a crude way to display information, but sufficient for the purposes of this assignment.  If you wish, you may modify the user interface to improve how student and grade information is displayed.