Fall 2012, The College of Saint Rose

Lecture 25: Classes; Course Wrapup
Date: Thursday, December 6, 2012

Agenda

• Announcements
• Final projects continue - due Monday at 4 PM, usual late penalty rules apply
• Missing course evaluations
• Final Exam information
• location update for 4:10 sitting: AH 205
• review: Monday 6-8 PM, Albertus 216
• other details on lecture 24 page
• Lecture assignment 24 recap
• Defining classes
• In-class exercise

We will work together to develop a Java program that will include a class to represent a circle and another class that will create and work with some circles. You may work alone or with a partner on this exercise in class.

Our circles will not actually be drawn on the screen, but we will store information that could be used to do so. We will maintain 3 pieces of information about the circles:

• its center coordinates
• its color

We will develop a class called Circle which stores the above data, and includes methods to create a circle, query its center, query its radius, query its color, query its top, bottom, left end right edges, query its diameter, and obtain a String description of the circle. Additional methods will allow the center, radius, diameter, and color to be modified.

We will also develop a class called CircleMaker that we will use to test the constructors and other methods of the Circle class.

Submit your Java files Circle.java and CircleMaker.java in Blackboard under the "Lecture Assignment Submissions" category to the "Lecture 25 In-Class Exercise" item. This will earn you 10 lecture assignment points. Make sure your name(s) is/are in each of the files you submit.

No New Lecture Assignment

Obviously.

But here are some exam practice questions you might want to look at:

• 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.

• Modify the following to use one or more methods to make the code simpler and more readable:
```public class NeedsMethod {

public static void main(String[] args) {

int fact = 1;
for (int number = 5; number >= 1; number--) {
fact *= number;
}
System.out.println("5! = " + fact);

fact = 1;
for (int num = 9; num >= 1; num--) {
fact *= num;
}
System.out.println("9! = " + fact);

int f = 1;
for (int number = 12; number >= 1; number--) {
f *= number;
}
System.out.println("12! = " + f);
}
}
```
• Gaddis Programming Challenge exercise 5, p. 359.

Examples