Concordia University

             COMP 248 – Winter 2019

                        Assignment 3

Due Date: By 11:55pm March 22, 2019

Evaluation: 6% of final mark (see marking rubric at the end of handout)

Late Submission: none accepted

Purpose: The purpose of this assignment is to help you learn Java loops, control flow statements: if, if/else, switch, and creating a simple class.

CEAB/CIPS Attributes: Design/Problem analysis/Communication Skills

General Guidelines When Writing Programs:

– Refer to handout of assignment 1

Question 1

It is quite common at that time of the semester where you start speculating what grade you are going to get in a particular course and how that grade will affect your GPA. This assignment will help you and your friends to do just that. In this assignment, you will create a GPA calculator for an undergraduate Concordia student.

The letter grades and their weights the program must support are:

1

The program will start by asking the user about his/her current GPA and the number of credits he/she has accumulated so far.

2

If the student is a new student, then he/she will enter 0 for the number of credits and the program will NOT ask the student about his/her current GPA since that question would be considered useless.

3

Here you are an example of a run with all valid data:

4

The program, will display the above menu, once it has gotten:

1. the total number of credits the student has achieved so far

2. the student’s current GPA

3. The courses the student is currently taking. These are the courses the student wants to check their effect on his/her GPA

When menu option 1 is chosen, the following will be displayed:

5

So, the point of option number 1 is to display the info given to the program

When the user chooses option 2, the new GPA is calculated and displayed.

6

Notice here that the menu option keeps displaying after executing each option.

The calculation formula for the new GPA is as follows:

x = (current GPA * total number of credits achieved so far) + ∑ (weight of grade *course credit) for all current courses)

y = total number of credits achieved so far + ∑ (course credit) for all current courses

New GPA = x/y

For example, for the above example,

x= (4.0*120) + (4*3) + (3*3) + (4*3) = 513 y= 120 + 3 + 3 + 3 = 129

New GPA = 513/129 = 3.976

When the user chooses option 3 , a list of the current courses will be listed and the user will be asked to choose the course number of the course to be deleted.

7

After the deletion of course number 2, you can see the effect of that on the GPA:

8

Option 4 is used to add a course:

9

After adding this 6 credit course with a letter grade of D, we can check the effect of that on the GPA

10

Option 5, will make the program terminate.

There are lots of data validations that have to be done: Here you are some examples:

1.Number of credits accumulated so far must be greater than or equal to 0; it can not be a negative number

11

2. Current GPA has to be between 0 to 4.3 inclusive

12

3. Number of courses to add to the system has to be greater than 0

13

4. Number of credits of a course has to be greater than 0

14

5. Letter grade has to be a valid one

15

6. The chosen menu option has to be between 1 and 5 inclusive

16

Some technical requirements you must abide by:

1. Use a switch/case statement to handle the menu options.

2. Use one array to store the added course names

3. Use one array to store the added course credits

4. Use one array to store the added course letter grades

5. Use a constant for the maximum number of courses the system can support

6. If the user tries to add more courses, display an error message

Question 2

Create a simple class Course with its accessors, mutators, and toString methods. There should only be a default constructor. The data members of the course class are as follows:

name € which is a string

credits € which is a double

letterGrade € which is a string

Two constructors are needed: a default one and a parameterized one.

The toString method when called, it should return a string representation of the course object in the following format:

Course name: <name> Number of credits: <credits> Grade: < letterGrade>

where < name>, < credits> and < letterGrade> are the content of the attributes of the object.

Create a driver class to test the course object. In the driver class, you need to instantiate three Course objects for the following three courses and then the toString method to display the content of each one of them.

17
18
19