write a Java application
Posted on 2011-09-07
A local coffee shop sells a variety of different items shown below to their customers. You are asked to write a Java application that can be used to keep track of these items. Additionally, this program provides a way to print out a listing of the items.
Item Name Price Coffee $1.00 Water $2.00 Milk $1.50 Bagel $1.25 Donut $0.75
Your program will create a class, named Item. This class has the following: * A String instance variable to hold the item name * A double instance variable to hold the price * A constructor that takes a String and double to initialize the instance variables * A get and set method for each instance variable
Once you have this class created, you write a second class named CoffeeDriver. This class has the following methods: * sortName – this method sorts the array of items by item name and then displays the name and price of all items on the screen * sortPrice – this method sorts the array of items by item price and then displays the name and price of all items on the screen * main - It creates an array of Item objects using the data above to set each Item's information. After initializing the array, prompt the user for how they want to see the list – sorted by name or price. Then call the appropriate method.
Be sure your program demonstrates good programming style (appropriate comments, identifier names, indenting, etc).
Although it is not required to look this way, your output might look something like the following:
(appropriate comments, identifier names, indenting, etc).
Although your output is not required to look this way, it might look something like:
Please enter a value:1.23
Please enter a value: 2.34
Please enter a value: 3.45
Please enter a value: 4.56
Please enter a value: 5.00
The sum of these values is $16.58
The average of these values is: $3.32
The values higher than the average are: $3.45