Computer Science homework help

CS 219 – HOMEWORK 1

due: Thu, 8/23/18

HOMEWORK SUBMISSION POLICIES:

· Put all of your work, even project source code and project output, into a single homework document, and submit that document to the course website by midnight of the day that the homework is due. Put your name at the top of that document.

· Make sure that the problems in your homework document are in the same order as the problems in the homework assignment.

· In your homework document, make sure that you use monospace font for your project source code and project output. The monospace font ensures that text that’s supposed to be aligned stays aligned when it’s printed. If your printed source code is not aligned properly, you will lose style points. To achieve monospace font, highlight the relevant text, right click, and select Font. In the Font window, search for Courier New, select it, and click OK to apply your font selection.

MANDATORY UNGRADED WORK:

Read my Getting Started with Eclipse tutorial. As you read the tutorial, perform the steps as described in the tutorial. If you haven’t done so already, print my Homework Assignment Guidelines – Java Programming document and my Java Coding Conventions Guidelines document. You must follow the guidelines found in those documents. Read the documents now!

PRACTICE PROJECT (Do not submit an answer because the answer will be provided):

Provide a complete program that handles the processing of Rectangle objects. Your Rectangle class should contain:

· two instance variables, height and width, that keep track of a rectangle’s dimensions

· a static variable, numOfRectangles, that keeps track of the total number of instantiated rectangles

· A 0-parameter constructor

· A constructor that receives two parameters, height and width

· getNumOfRectangles – a method that retrieves the number of instantiated rectangles

· addHeight – a method that receive an int parameter and adds the parameter’s value to the height variable (Note: The addHeight method must be implemented so as to enable method call chaining.)

· addWidth – a method that receive an int parameter and adds the parameter’s value to the width variable (Note: The addWidth method must be implemented so as to enable method-call chaining.)

· printArea – a method that print’s the rectangle’s area

Write your code such that the following main method would produce the output shown below.

public static void main(String[] args)

{

Rectangle r1 = new Rectangle();

r1.printArea();

Rectangle r2 = new Rectangle(2, 4);

r2.printArea();

r2.addHeight(3).addWidth(3);

r2.printArea();

System.out.println(

“Total number of rectangles = ” + Rectangle.getNumOfRectangles());

} // end main

Output:

Rectangle’s area = 0

Rectangle’s area = 8

Rectangle’s area = 35

Total number of rectangles = 2

As always, your program should mimic the output format precisely.

Submit answers for all of the following questions.

EXERCISES:

The following exercise questions refer to material in the Getting Started with Eclipse tutorial.

1. In Eclipse, what is the name of the file that stores a project’s settings? (The project-settings file is different from the file that stores coding-style preferences.)

2. What button should you click to terminate the currently running program?

3. When you print your output, why is it important to use monospace font for your program output and program source code?

PROJECT:

Provide a complete program that stores scores for individual exams and calculates the average score and grade for all exams combined. Specifically, provide an ExamScore class that contains these attributes:

· Named constants for the letter grade minimum cutoff values. Use A = 0.9, B = 0.8, C = 0.7, and D = 0.6. Generate an F for a score less than .6

· The number of exams.

· The maximum number of points possible on each exam (every exam has the same number of maximum points, so use a variable that’s shared between all the objects).

· The total points earned on all exams combined.

· The points earned on a particular exam.

For each of your variables, think about whether it should be a named constant, a class variable, an instance variable, or a local variable. As always, use the most appropriate kind of variable for the variable’s intended purpose.

You are welcome to provide additional constructors and methods, but at a minimum, your ExamScore class should implement these constructors and methods:

· 1-parameter constructor –Assign a passed-in earned points value to the exam object’s earnedPoints attribute. Update the total number of exams and the total earned points for all exams combined.

· setMaxPointsForEachExam – A standard mutator method for the maxPointsForEachExam variable.

· printScore – Print the calling object exam’s score and letter grade. For additional details, see the output, below.

· printCombinedScore – Print the score and letter grade for all grades combined. For additional details, see the output, below.

Use appropriate modifiers for methods. The modifiers we’ve discussed so far are private, public, and static. You are required to use a helper method if it is appropriate to do so.

Provide a main driver method. It should:

· Call setMaxPointsForEachExam such that 100 is assigned as the maximum score for each exam.

· Instantiate four ExamScore objects and store them in the variables exam1, exam2, exam3, and exam4. In the instantiations, initialize the objects to these values:

exam1: 70.5 earned points

exam2: 90 earned points

exam3: 79.5 earned points

exam4: 78 earned points

· For exam1, exam2, and exam3 (but not exam4), call printScore.

· Call printCombinedScore.

Output, using the main driver method described above:

On this exam, you earned 70.5 out of 100.0 possible points: C

On this exam, you earned 90.0 out of 100.0 possible points: A

On this exam, you earned 79.5 out of 100.0 possible points: C

On all exams combined, you earned 318.0 out of 400.0 possible points: C

As always, your program should mimic the output format precisely.

EXTRA CREDIT (2 pts):

Add functionality to your ExamScore class such that it can calculate the average score and grade with the lowest exam score thrown out. If you call your new printCombinedScoreWithLowestRemoved method after instantiating four exams as described above, your program should display this:

With your lowest exam thrown out, you earned 247.5 out of 300.0 possible points: B

Your printCombinedScoreWithLowestRemoved method should not permanently remove the lowest score. So the output from printCombinedScore should be the same regardless of whether you call it before or after you call printCombinedScoreWithLowestRemoved.

"Get 15% discount on your first 3 orders with us"
Use the following coupon
FIRST15

Order Now