COMP 110-001 - Introduction to Programming (Spring 2009)
Lab 6
25 points
Assigned: March 20th
Due: March 26th by midnight
Description
This lab is based on Ch. 6 Ex. 1 & 2 of your text, Savitch & Carrano, "Java: An Introduction to Problem Solving and Programming", 5th edition.
Part 1
Create a class called "Time" that represents the time of day. It has attributes for the hour and minute. Valid hour values range from 0-23 and valid
minute values range from 0-59.
- a. Write a default constructor that initializes the time to 0 hours, 0 minutes
- b. Write a private method isValid(hour, minute) that returns true if the given hour and minute values are valid
- c. Write a method setTime(hour, minute) that sets the time, but ONLY if the given values are valid
- d. Write a second constructor whose function is analogous to that of the setTime method from part c
Part 2
Create a class called "TaxUtils" that will bundle together several static methods for tax computations. This class should NOT have a constructor. Its attributes are
- basicRate - the basic tax rate as a static double variable with a value of 4%
- luxuryRate - the luxury tax rate as a static double variable with a value of 10%
Its methods are
- roundToNearestPenny(price) - a private static method that returns the given price rounded to the nearest penny. For example, if the price is 12.567,
the method will return 12.57
- computeCostBasic(price) - a static method that returns the given price plus the basic tax, rounded to the nearest penny
- computeCostLuxury(price) - a static method that returns the given price plus the luxury tax, rounded to the nearest penny
- setBasicRate(newRate) - a static method that changes the basic tax rate to newRate
- setLuxuryRate(newRate) - a static method that changes the luxury tax rate to newRate
HINT: See the beginning of section 6.3 in the text for a strategy that can be used to round to the nearest penny.
Part 3
Create a class called "TaxUtilsTester" that will perform some basic tests on your "TaxUtils" class. At the very LEAST, your TaxUtilsTester must do the following
- Set the basic tax rate
- Set the luxury tax rate
- Make a call to computeCostBasic using a price of your choosing and check that the correct value is returned
- Make a call to computeCostLuxury using a price of your choosing and check that the correct value is returned
Submission
Before submitting, make sure that each .java file contains a properly edited Program Header.
For this assignment you will need to create a Jar file that contains the source code for Time.java, TaxUtils.java AND TaxUtilsTester.java that you edited as part of
this assignment. Follow these instructions for creating a Jar file.
The Jar file you submit must be named yourlastname_lab6.jar, where yourlastname is your last name
Submit yourlastname_lab6.jar via the UNC Blackboard System under "Assignments → Lab 6"
before the deadline.
Grading
- 4 points Part 1
- 8 points Part 2
- 8 points Part 3
- 2 points Jar file submitted and named correctly
- 3 points Program Headers edited correctly