CS CAMP 2.0: Outline for OOP and Java

I

II

Double temperature = new Double(98.6);
Integer age = new Integer(18);
Boolean failed = new Boolean(grade < 70);

III

IV

Possible Lab Assignments:

Given:
int a, b, c;
create expressions that calculate the roots of the equation ax^2 + bx + c = 0 (assuming that the two real roots exist) and assign them to two double variables x1 and x2. Use a temporary variable to hold sqrt(b^2 – 4*a*c) in order not to compute it twice.

Create a method
public int convertToHumanAge(int dogYears)
that converts a dog’s age to the corresponding human age. Assume that a dog’s first year corresponds to a human age of 13. After that every three years in a dog’s life correspond to sixteen years in human life. The method returns the corresponding human age, rounded to the nearest integer. Write a Java program to test your method.

Create a Boolean method isLeapYear(int year) that returns true if year is a leap year and false otherwise. A leap year is a year that is evenly divisible by 4 and either is not divisible by 100 or is divisible by 400. For example, 2000 and 2004 are leap years, but 2003 and 2100 are not.

Create a Java method totalWages, which calculates the total earnings for a week based on hours worked and the hourly rate. The pay for overtime (hours worked over 40) is 1.5 times the regular rate. For example, totalWages(45, 12.50) should return 593.75.

Priority mail costs $3.50 for one pound or less, $3.95 for over one pound but not more than two pounds, and $1.20 for each additional pound (or fraction) above two pounds. First Class mail costs 37 cents for the first ounce and 21 cents for each additional ounce (or fraction), up to 13 ounces, after which Priority rates apply. For example, Priority Mail for 5 oz Costs $3.50 and for 4.5 lbs - $7.55; First Class mail for 3.5 oz costs $0.97 and for 15 oz - $3.50.

Create a Java method double calculatePostage(double ounces, char mailType) to allow calculation of postage.

Other Materials