COSC4301
Program-1
Due: 9/13/2012
Simple I/O and Repetition
Task:
Modify
the following program so that
1.
There
are 10 different items for purchase, instead of just one,
2.
For
each item, you enter the number of items purchases followed by its unit price
(just as it is right now),
3.
For
each item you enter, the program will print out on the next output line the
following three values:
a.
InputCount
(starting from 1)
b.
Quantity
c.
Unit
price
4.
After
all ten input items have been processed, the total sale price including the
sales tax (8.25%) will be printed out followed by the current finishing message
the current program shows.
import
java.util.Scanner;
public
class SelfService
{
public
static void main(String[] args)
{
Scanner
keyboard = new Scanner(System.in);
System.out.println
("Enter number of items purchased.");
System.out.println
("followed by the unit cost.");
System.out.println
("Do not use a dollar sign.");
int
count = keyboard.nextInt( );
double
price = keyboard.nextDouble( );
double
total = count*price;
System.out.printf("%d
items at $%.2f each.%n", count,
price);
System.out.printf("Total
amount due $%.2f.%n", total);
System.out.println("Please
take your merchandise.");
System.out.printf("Place
$%.2f in an envelope %n", total);
System.out.println("and
slide it under the office door.");
System.out.println("Thank
you for using the self-service line.");
}
}