Hey, first time poster...and a little desperate. I hate asking for help; however, with a super limited time frame (a little more than 24 hours) and work, I really need help with this assignment. The main thing is for the "TestCashier" class, I cannot modify what is there, only add.
First I'll put up the assignment, followed by my code so far. I'm mainly having a problem understanding how to convert my input into output, using the code I'm given in TestCashier
"Write a class called Cashier that directs a cashier how to cash goods and give change to customers. The typical cashier operations are as follows:
(a) Enter the name of and price of each item in the cash registering machine.
(b) The machine totals the cost of the items as they are entered.
(c) The customer tenders an amount to pay for the goods (We assume the amount covers the total).
(d) The cash machine computes:
i. The number of items purchased
ii. The average price of each item
iii. The number of coin denominations that the customer should receive. That is, the number of silver dollars, quarters, dimes, nickels, and cents the customer should receive in turn. In addition.
Here is a typical test class.
class TestCashier
{
public static void main(String[] arg)
{
Cashier c = new Cashier();
String name = GetData.getWord(“Enter name of item”);
double price = GetData.getDouble(“Enter price of item”);
c.add(name, price);
name = GetData.getWord(“Enter name of item”);
price = GetData.getDouble(“Enter price of item”);
c.add(name, price);
// Add a few more entries of your own
// Now average the price of the items
c.average();
// Make payment
double amount = GetData.getDouble(“Enter amount of money for payment”);
c.tendered(amount); // Twenty dollars were tendered
c.makeChange();
generateReceipt(c);
}
static void generateReceipt(Cahier c)
{
// Write the necessary code that will generate a customer’s receipt.
// The output must be displayed in a scrollable pane
}
}
Description of the output:
The output should be displayed in a scrollable pane, and have the following features:
• The first line displays the name of the establishment.
• Second line reads something like this: Welcome – thanks for stopping, followed by the current date
• The list of items displayed, one item per line – the name and price,
• The sum of all the items
• The amount of money tendered
• The amount of change in $ and cents
• The number of items purchased
• The average price for each item
• The change given in coin denominations
See below, except that this output must be displayed in a scrollable pane.
Bread............ 2.99
Chicken..........6.79
Egg..................3.07
______________
Total ……….$12.85
Amount tendered = $20.00
The change is $7.15
There were 3 items
The average price is $4.28
The change includes
7 dollars
0 quarters
1 dimes
1 nickels
0 cents
NB: Use the class GetData to enter the data.
"
************************************************** ************************************************** ************************************************** **********************
(TestCashier)
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import java.text.NumberFormat;
import java.text.DecimalFormat;
import java.util.Locale;
class TestCashier
{
public static void main(String[] arg)
{
Cashier c = new Cashier();
String name = GetData.getWord("Enter name of item");
double price = GetData.getDouble("Enter price of item");
c.add(name, price);
name = GetData.getWord("Enter name of item");
price = GetData.getDouble("Enter price of item");
c.add(name, price);
// Add a few more entries of your own
// Now average the price of the items
c.average();
// Make payment
double amount = GetData.getDouble("Enter amount of money for payment");
c.tendered(amount); // Twenty dollars were tendered
c.makeChange();
generateReceipt(c);
}
static void generateReceipt(Cashier c)
{
// Write the necessary code that will generate a customer’s receipt.
// The output must be displayed in a scrollable pane
}
}
************************************************** ************************************************** ************************************************** **********************(Cashier; this is where I'm having the most trouble)
class Cashier
{
public String name;
public static double price;
public String add;
public Cashier()
{
}
public void add(name, price)
{
}
}
************************************************** ************************************************** ************************************************** **********************
(GetData, this one I have correct I believe)
import javax.swing.JOptionPane;
class GetData
{
static String str;
static Double getDouble(String s)
{
str = JOptionPane.showInputDialog(s);
return Double.parseDouble(str);
}
static Double getAmount(String s)
{
str = JOptionPane.showInputDialog(s);
return Double.parseDouble(str);
}
static String getWord(String s)
{
return JOptionPane.showInputDialog(s);
}
}
************************************************** ************************************************** ************************************************** **********************
If anyone can help me I'd greatly appreciate it. Normally I don't ask for help but this is all due tommorow evening, and all my plans to work this past weekend were crushed by the insanity that is my social life.