CSCI 51 Spring 2009
Problem Set 1: 100 points
Assigned: Thursday, January 22
Due: Monday, February 2 at 11:59 pm
Description
You are responsible for creating four java classes, Time, Temp, Money,
WireTransfer. Those exact names
are important. In the end you submit a single folder containing
the four respective java files.
Time: 25pts
Write a Java class named Time in a file
named Time.java that does the following:
1. The main method in the class reads
from the keyboard an integer representing a number of seconds, then
prints the equivalent amount of time as a combination of hours,
minutes, and seconds. For example, if
9999 is read in to mean 9999 seconds, the output would be 2 hours, 46
minutes, and 39 seconds. You may
assume that the user will enter a reasonable number both in size and
format as input, say it will be smaller
than 86,400.
2. Using the number that you read in in part (1) above as the time of
the day, create variable names hour,
minute, and second, and assign them values that you calculated. Use a
24-hour clock, so that at
2:00pm the value of hour is 14. Make the program calculate and print
the number of seconds remaining
in the day.
3. Make the program calculate and print the percentage of the day that
has passed.
Temp: 25pts
Write a Java class named Temp in a file
named Temp.java that reads a Fahrenheit temperature from the user as
a floating point number, converts it into Celsius, and prints the
result to the user in a friendly formatted output. In
this problem the input is entered by a user on the keyboard. By
’reading’ I mean that your program should instruct
the user of your program to enter a number from the keyboard and read
it, rather than assigning a number yourself
to a variable in your program at as you write your program, i.e., at
compile time. That is, reading it from the
keyboard and assigning the number read in means that the assignment of
the number to a variable is happening at
run time.
Money: 25pts
Write a Java class named Money in a
file named Money.java that reads from the keyboard a real number
representing a monetary amount. Then determine the fewest number of
each bill and coin needed to represent
that amount, starting with the highest (assume that a ten dollar bill
is the maximum size needed). For example, if
the value entered is 47.63 (forty-seven dollars and sixty-three cents),
then the program should print the equivalent
amount as:
4 ten dollar bills
1 five dollar bills
2 one dollar bills
2 quarters
1 dimes
0 nickles
3 pennies
Warning: If you are losing a cent in some test cases, don’t worry about
it. It has to do with how floating point
numbers are represented in hardware. If you want to avoid the problem,
just convert the amount that you read in
into an int, i.e., cents, and deal with it with integer divisions from
then on.
WireTransfer: 25pts
Write a Java class named WireTransfer
in a file named WireTransfer.java that reads from the keyboard a real
number
representing an amount in euros to be transferred. This class then
provides a receipt of this transfer in dollars that includes
$45 for a transfer fee and $1.53 per euro exchange rate. For example,
if the input is 650, the output should be like the
following:
Wire Transfer Fee $45.00
Amount * 1.53 $994.50
________________________
Total
$1039.50
Notice the two decimal places on every amount.
What to Turn in:
The four java files. That is ONLY the java
files, not the class files. Attach the .java files to your submission
through the Sakai assignments.
Additional requirements
Remember to place a header comment in each file that says something
like this:
/*
(Your Name)
CSCI 51, Spring 2009
Problem Set 1
Time.java (for example)
*/