Assignment 1
Be sure to type up your answers so you can submit them electronically on the
BlackBoard Connect system. You may complete this assignment individually.
Make sure all your files have your full name and student number on it.
Type up your answers using Eclipse.
The file format of the Java program you are to submit must be .java.
This assignment is marked out of 55 points.
Due Date
January 25, 2014, 11:59AM (just before noon).
24 Hour Silence Policy
Due to the large class size and the potential volume of questions, we are
implementing a 24-hour silence policy. This means that any questions posted on
the discussion forum in the 24 hours immediately preceding the assignment
deadline may not get answered in time. This does not mean that we will
stop answering questions the moment the day before the deadline arrives, it just means
that we cannot promise all the questions will be answered in time, due to our
prior engagements, such as other classes and meetings we have.
For this reason, please be sure to attempt the assignment early, and try to
complete it as if it were due two days prior to the real deadline.
In any case, we will try to answer all the questions that show up on the
discussion forum. Note that questions sent to emails will not be
answered, as we want all course related material to be viewed for everyone's
benefit.
What You Are Given
There are 2 questions in this assignment. The first question is to review
some major concepts that you should be familiar with from COSC 111.
The second question gets you to practice inheritance.
Question 1 [30 points]
In this question, define a class called GradesTracker that helps a
student keep track of his/her course grade so far. The data we keep track of
will be modeled based on the COSC 121 evaluation criteria. That is, we will
have 3 assignments that are worth 20% (weighted equally), 9 labs that are
worth 20% (weighted equally), 1 midterm that is worth 20%, and a final exam
that is worth 40%.
The criteria used to evaluate your solution for this class are:
- 2 points: Follow the standard class template to define the
GradesTracker class.
- 2 points: Using an array to keep track of assignment marks, and a
separate array to keep track of lab marks.
- 1 points: Using constants as appropriate to keep the code
readable and easy to maaintain.
- 3 points: Initializing all your attributes in your constructor.
Moreover, you must use a loop to give default values to your array
elements.
- 3 points: Follow the recommended encapsulation guidelines.
- 5 points: Write a method called enterGrades() that asks
the user to enter various course marks if they are available. To keep things
simple, make all the marks out of 100%.
To keep your code clean, you must use a loop to keep asking the user
to enter assignment and lab marks as long as they are still available.
You may want to separate out all the work that needs to be done by this
method into several, smaller helper methods.
- 8 points: Write a method called calculateGrade() that
calculates all the marks entered and store the computed course grade in your
attribute. Note that if a lab mark has not been entered, it is treated as a
score of 0, because your course grade only reports what you have so far. If
you are not sure how the calculations work, check out the sample output to ensure all the numbers make
sense.
To keep your code clean, you must use a loop to tally up all the
entered assignment and lab marks.
You may want to separate out all the work that needs to be done by this
method into several, smaller helper methods.
- 1 point: Write a method called getCourseGrade() that
serves as the accessor to your course grade attribute so it can be used to
retrieve your course grade by the test class.
5 points: Don't forget to test your program.
Write a test class called TestGradesTracker that creates a
GradesTracker object, lets the user enter grades, calculates the
course grade, and prints out the computed grade on the screen.
Do the following four test cases for your code to ensure your program works:
- Testing to get your mark just before the final exam
Enter all assignment marks, all lab marks, and midterm mark.
Compute course grade.
- Testing to make sure it works even if no marks are available
Don't enter any marks for anything.
Compute course grade.
- Testing to get marks so far if only one set of marks are available
Enter all assignment marks, but nothing for the others.
Compute course grade.
- Testing to get overall mark when some marks are available
Enter two assignment marks, 5 lab marks, a midterm mark, and a final exam
mark.
Compute course grade.
See sample output for these cases. When you test
your program, be sure to include these 4 cases in your output. Save your
output into a file called Grades-Output.txt.
Question 2 [25 points]
4 points: Define a class called Reading that keep track of the
number of pages, year of publication, and the title. This class will serve as
the parent class for the others you will define below. Be sure you do the
following:
- Make sure you include a constructor and initialize all the attributes.
- Define an accessor and mutator for each attribute.
- Define a toString() method that prints out the basic
information in your class.
Next, define three classes that model various types of readings named as
followed:
Novel,
Textbook, and
Newspaper.
Each child class will also need to handle the following:
-
Each novel has an author, a location setting, and a main character. Define
associated accessors and mutators for these attributes.
- A textbook has a subject, an author, and an assigned number of pages to
read. Here, we will override the parent's number of pages and use that
attribute to store how many pages are in the assigned reading.
Define associated accessors and mutators for these attributes.
-
A newspaper has a publisher and the number of articles in it.
Define associated accessors and mutators for these attributes.
-
Each child class will need to have its own toString() method that
uses the parent's toString() method.
-
Don't forget to include a constructor in each class and initialize all the
attributes.
Each class definition will be worth 5 points each.
Make sure you put shared variables and methods in the parent class. You may
wish to use super and protected as needed. Also, be sure to
not have shadowing variables in your classes.
3 points:
Don't forget to follow encapsulation rules.
3 points:
Write a test class called TestReading that creates an object for each
of the child classes defined above. You should demonstrate your classes work
by printing out the information in each of these readings, then changing some
of the information via mutators, and re-printing those objects to show the
changes have been made.
You can see the sample output provided here.
Save your output into a file called Reading-Output.txt.
What to Submit
Be sure to comment all the methods and attributes for clarity.
For this assignment, submit the following:
- GradesTracker.java
- TestGradesTracker.java
- Grades-Output.txt
- Reading.java
- Novel.java
- Textbook.java
- Newspaper.java
- TestReading.java
- Reading-Output.txt
- Include your full name and student ID.
- List the full names of the people who helped you in this assignment
(include students and TAs if applicable), and mention what they helped you with
-- failure to do so honestly will result in a lower mark and may be reported
for academic discipline