Computer Science 523
Advanced Programming

Summer 2014, The College of Saint Rose

Lab 3: Custom Classes
Due: 4:30 PM, Tuesday, June 10, 2014

In this week's lab, you will practice defining and using custom classes.

You may work alone or with a partner on the programming portions of this lab. Only one submission per group is needed.

Getting Set Up

To get your BlueJ environment set up for this week's lab assignment, start BlueJ and choose "New Project" from the "Project" menu. Navigate to your folder for this course and choose the name "Lab3" (no spaces) for the project.

Create a document where you will record your answers to the lecture assignment and lab questions. If you use plain text, call it "lab3.txt". If it's a Word document, you can call it whatever you'd like, but when you submit, be sure you convert it to a PDF document "lab3.pdf" before you submit it.

Lecture Assignment Questions

We will usually discuss these questions at the start of class on the lab due date, so no credit can be earned for late submissions of lecture assignment questions.

LA Question 1: Gaddis Find the Error exercises 1-4, p. 287. (2 points total)

LA Question 2: Write a method that computes and returns the shipping cost of an item for an online store. The store's shipping policy states that shipping costs 75 cents per item, plus 25 cents for each ounce of product weight. There is an exception for items priced $100.00 or more, for which shipping is free.

So for an item that costs $12.99 and weighs 6 ounces, the shipping cost is computed as $0.75 + 6 * $0.25 = $2.25. For an item that costs $150.00, shipping costs $0.00.

Also write calls to the method that compute the shipping costs for the 2 above examples, placing the results in variables named cheapItem and expensiveItem. (3 points)

LA Question 3: Gaddis Algorithm Workbench exercise 2, p. 356, parts a and b only. (2 points)

LA Question 4: Gaddis Algorithm Workbench exercise 4, p. 357. (3 points)

LA Question 5: Write a new mutator method for the Ratio class in the Ratios example that takes an int parameter and multiplies the value of the ratio by that number. Recall that you can multiply the value of a ratio by a value by multiplying its numerator by that number. Do not worry about reducing to lowest terms or any other simplifications. (5 points)

LA Question 6: Write a new mutator method for the Ratio class in the Ratios example that takes a Ratio parameter and multiplies the value of this ratio (the one whose method you are executing) by that ratio (the one you received as a parameter). Recall that you can multiply a ratio by another by multiplying their numerators to find the new numerator, and their denominators to find the new denominator. (5 points)

LA Question 7: Write a non-destructive method for the Ratio class in the Ratios example that takes a Ratio parameter and adds together the value of this ratio by that ratio, but returns a new Ratio that contains the sum. Neither this ratio (the one whose method you are executing) nor the other (the one you received as a parameter). Recall that you can compute the sum of two fractions a/b and c/d by computing the numerator of the sum as ad + bc, and the denominator as bd. (5 points)

Practice Programs

Practice Program: Gaddis Programming Challenges exercises 10 and 11, p. 361-362. For exercise 10, write the main method that tests the SavingsAccount class in a class called SavingsAccountSimulator. For exercise 11, write the main method that uses the SavingsAccount class to track the month's transactions from the input files in a class called SavingsAccountMonth. (15 points total - see breakdown)

Practice Program: Gaddis Programming Challenges exercise 12, p. 362. Write the the main method that demonstrates the Coin class right in the Coin class. (10 points)

Programming Assignment: Tracking Student Grades

Your programming task for this week is to write a program, using a custom class, to extract and print some information from a file of student grading data.

Your program will read a list of student grading information from a file which contains one student's information per line. Each line will consist of a single word name, followed by 3 numbers representing scores on labs, a midterm exam, and a final exam. You may assume there is at least one valid line in the file, but your program should work for any non-zero number of lines. The only prompt you should issue and the only information you should supply to your program using the keyboard is the name of the file that contains all of the student information.

As you read the lines from the file, your program should keep track of the student who has the first name alphabetically, and the highest and lowest score in each category, and the highest and lowest total score (the sum of the three categories). At the end, print out the information for the student whose name/scores was the "winner" in each category. As we did in the class example for items purchased, you should break ties for the "lead" in any category by using the first student with that value for the category.

For example, given the following input file:

Brad 87 45.8 100
Alice 21 11 12
Greg 23 88 32
Bonnie 83 92.8311 88
Jeannie 77 77.77 77.77
Roberta 98 92 100
Cora 95 94.923 90

an appropriate output would look like:

First student, alphabetically:
Alice, labs: 21.00, midterm: 11.00, final: 12.00, total: 44.00
Student with the lowest labs score:
Alice, labs: 21.00, midterm: 11.00, final: 12.00, total: 44.00
Student with the highest labs score:
Robert, labs: 98.00, midterm: 92.00, final: 100.00, total: 290.00
Student with the lowest midterm score:
Alice, labs: 21.00, midterm: 11.00, final: 12.00, total: 44.00
Student with the highest midterm score:
Cora, labs: 95.00, midterm: 94.92, final: 90.00, total: 279.92
Student with the lowest final score:
Alice, labs: 21.00, midterm: 11.00, final: 12.00, total: 44.00
Student with the highest final score:
Brad, labs: 87.00, midterm: 45.80, final: 100.00, total: 232.80
Student with the lowest total score:
Alice, labs: 21.00, midterm: 11.00, final: 12.00, total: 44.00
Student with the highest total score:
Robert, labs: 98.00, midterm: 92.00, final: 100.00, total: 290.00

Notes:

Question 1: Instead of using a class to encapsulate the information about a student, your main method could have kept track of all of the pieces of information about the "leader" in each category in variables of primitive types and/or String references. Compare how the program you wrote and a program written in this alternate manner would affect the code in terms of (i) number of variables needed, (ii) lines of code needed, (iii) readability of the code, and (iv) complexity of updating the program to add a new category, e.g., a programming project. (5 points)

Submitting

Before 4:30 PM, Tuesday, June 10, 2014, submit your lab for grading. There are two things you need to do to complete the submission: (i) Copy your file with the answers to the lecture assignment and lab questions into your project directory. Be sure to use the correct file name. If you prepared your answers in Word, export to a PDF file and submit that. (ii) Upload a copy of your lab (a .7z or .zip file containing your project directory) using Submission Box under assignment "Lab3".

Grading

This assignment is worth 100 points, which are distributed as follows:

> FeatureValueScore
Lecture assignment questions 25
SavingsAccount correctness 5
SavingsAccountSimulator correctness 5
SavingsAccountMonth correctness 5
Coin class correctness 7
Coin main method correctness 3
StudentGrades instance variables 3
StudentGrades constructor(s) 2
StudentGrades accessor methods 3
StudentGrades toString method 3
GradeTracker reads file name from keyboard 1
GradeTracker correct file I/O 2
GradeTracker processes one student 2
GradeTracker processes multiple students 3
GradeTracker correct answer in each category 9
GradeTracker report all answers at the end 4
GradeTracker keeps references only to current leaders 3
StudentGrades/GradeTracker comments 5
StudentGrades/GradeTracker good names and declarations 3
StudentGrades/GradeTracker formatting 2
Lab question 5
Total 100