This website is preserved for historical and scholarly reference and is no longer actively maintained.
CpSc 210, Section 1
Assignment 1
August 26, 2002
Due: Wednesday, September 4 at 11:59 p.m.
Assignment: printing a float float in dollars and cents format.
Total point value of assignment: 20 points
Not accepted late.
This assignment is to be done INDIVIDUALLY.
Assignment: Design and implement a class, PrintMoney, which must be stored
in a file named PrintMoney.java. (3 point deduction from grade for
failure to name file correctly!)
public class PrintMoney
{
public static void main ( String args [ ] )
{
// program goes here
}
}
Take variable of type float and print it in the format of dollars and
cents. Assume that the quantity will be rounded but DO NOT USE the
rounding feature of the language. That is, you must write code to
perform the rounding without changing the original float value.
Example 1. If the float variable contains 1234.455 your program
should print "1234.46", but the variable should still contain 1234.455.
Example 2. If the float variable contains 1234.454 your program
should print "1234.45", but the variable should still contain 1234.454.
Example 3. If the float variable contains 0.0, your program
should print "0.00".
Hint: Use % and / operators to produce temporary variables containing
the values you want to print.
Rounding action should be the same is Math.round function.
Grading Rubric:
2 pts. reasonable attempt to solve problem as assigned
1 pt. also compiles
3 pts. style standards (includes clarity)
Your name must be printed as a comment at the beginning of file.
A description of what this program does must immediate follow name.
Indent exactly 3 or 4 spaces. Be consistent. See handout examples.
Every Java statement must begin on a separate line.
The first operation of your program must be to print your name,
followed by "CPSC 210", the assignment number, and a description of
what program does.
The following 14 points are available only for code that compiles
and runs without error.
2 pts. program output clearly shows original float value and
value that will be printed.
2 pts. program adequately tests correctness of code (in the opinion
of the grader).
10 pts. program always works correctly (with our code).
Other requirements:
Follow the style standards to be found on your instructor's
web page for CPSC 210.
Submit your program using the handin command. There is a link to
the handin description on the CPSC 210 lab page (www.cs.clemson.edu/~lab210).