Spring Semester 2005
In this lab you will have to implement three problems.
Some help will be offered (posted) but Tuesday afternoon.
Here are the problems:
In all three cases you will need to make use of
Here are now the details on the above problems:
1. The Vending Machine. (The
Write a program that simulates a vendor that sells books
of stamps which are worth 3 dollars and 40 cents each. (The
vendor only sells whole books, each book is $3.40).
Vendor) starts by greeting the user, then
accepting money. Your vendor accepts the following monies only:
prompt> java Vendor Welcome. We sell stamps ($3.40) Please enter money: enter> nickel nickel dollar dollar quarter Thanks. Your credit is $2.35 I need $1.05 more. enter> cent cent Thanks. Your credit is $2.37 I need $1.03 more. enter> dollar quarter Thanks. Your credit is $3.62 The stamps are yours. Your change is: $0.22 Thanks for using this program.
Hints and Advice.
Your strategy should be simple:
Write a program that reads a set of floating-point data values from the input.3. The Standard Deviation (Part II)
When the end of file is reached, print out the count of the values, the average, and the standard deviation.
The average of a data setisThe standard deviation isHowever that formula is not as suitable for our task.
By the time you have computed the mean, the individual
xi's are long gone.
Until you know how to save these values, use the numerically less stable formulaYou can compute this quantity by keeping track of the count, the sum, and the sum of squares as you process the input values.
StringTokenizer to go twice through the values, using the first formula.
frilled.cs.indiana.edu%javac StdDev.java frilled.cs.indiana.edu%java StdDev Numbers> 90 90 92 86 4 numbers, average is: 89.5 Standard deviation is: 2.516611478423583 Numbers> 4 4 4 1 4 numbers, average is: 3.25 Standard deviation is: 1.5 Numbers> 0 number, average is: NaN Standard deviation is: NaN Numbers> 1 1 number, average is: 1.0 Standard deviation is: NaN Numbers> done frilled.cs.indiana.edu%