Results 1 to 7 of 7
- 03-11-2012, 06:16 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 4
- Rep Power
- 0
Programming homework, help needed!
Hey guys I am taking an introductory course to Java programming because I am a noob and I want to learn. Anyway I have this professor that doesn't really explain well what he wants us to do for our assignments, so i'm a bit confused on this one. I have to write three classes, a class, a test class, and a GetData class. If someone helps me compute the cashier/testcashier classes I will love you forever. Here is the assignment:
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) Cashier clears the cash register machine.
(b) Cashier enters the name and the price of each item in the cash registering machine.
(c) The customer tenders an amount of money 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 total amount of purchase
iii. The average price of each item
iv. 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.
Use the following class, TestCashier, as the basis for the test class.
Description of the output:Java Code: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 two 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); // For example 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 } }
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 – That is, the name of the product and price,
• The sum of all the items
• The number of items purchased
• The average price for each item
• The amount of money tendered
• The amount of change in $ and cents
• The change given in coin denominations
Here is an example of the form of how the output should be ( except that this output must be displayed in a scrollable pane).
Bread............ 2.99
Chicken..........6.79
Egg..................3.07
______________
Total ……….$12.85
The number of items purchased is 3 items
The average price per item is $4.28
Amount tendered is $20.00
The change is $7.15
The change includes
7 dollars
0 quarters
1 dimes
1 nickels
0 cents
NB: Use the class GetData to enter the data. This means that your program MUST consist of three classes: GetData.java, Cashier.java, and TestCashier.
My question is, how do I incorporate the GetData class to the other classes? And do I also need a TestGetData class? Because it clearly states at the bottom that I need only three classes so i'm a bit confused. If someone could please walk me through what I have to do for the GetData/Cashier classes it would be really helpfulLast edited by Fubarable; 03-11-2012 at 07:07 PM. Reason: code tags added
-
Re: Programming homework, help needed!
Your GetData class will have only two static methods, and you should probably know by now what those methods are since they're being used in the test code. As for creating a TestGetData class -- that's up to you. Myself, I'd give my GetData class a main method with which I would test out the code to be sure that it works well, and then before turning in the assignment, I'd remove the main method from this class.
- 03-11-2012, 11:21 PM #3
Member
- Join Date
- Mar 2012
- Posts
- 4
- Rep Power
- 0
Re: Programming homework, help needed!
This is what I have so far, and I am running into some compile errors. My test class does not recognize the getWord and getDouble from the getData class, not sure why this is. I will post my code from all three classes.
Java Code:import java.text.NumberFormat; import java.text.DecimalFormat; public class Cashier { //Variables private static int numberOfItems; private static double totalSum; private String name, s; private double amount, price, tendered, change, dollars, quarters, dimes, nickels, pennies; NumberFormat nf = NumberFormat.getInstance(); DecimalFormat df = (DecimalFormat)nf; //Constructor public Cashier() { this.name = name; this.price = price; price = 0; this.s = ""; } public double average() { return totalSum/numberOfItems; } public void Add(String name, double price) { totalSum = totalSum + price; s = s + name + "........" + price + "\n"; numberOfItems++; } public void tendered(double amount); { f.format(tendered = amount); }
Java Code:import javax.swing.JOptionPane; import javax.swing.JTextArea; import javax.swing.JScrollPane; import java.text.NumberFormat; import java.text.DecimalFormat; import java.util.Locale; import java.util.Date; import java.text.DateFormat; 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); name = GetData.getWord(“Enter name of item”); price = GetData.getDouble(“Enter price of item”); c.add(name, price); // Add a two 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"); tendered(amount); // Twenty dollars were tendered c.makeChange(); generateReceipt(c); } static void generateReceipt(Cashier c) { String r = "ABC Groceries Shop \n";If you can please point out what I am doing wrong it would help alot thank you!Java Code:import javax.swing.JOptionPane; public class GetData { static String str; static double getDouble(String s) { str = JOptionPane.showInputDialog(s); return Double.parseDouble(str); } static int getInt(String s) { str = JOptionPane.showInputDialog(s); return Integer.parseInt(str); } static String getWord(String s) { return JOptionPane.showInputDialog(s); } }Last edited by Fubarable; 03-11-2012 at 11:29 PM. Reason: code tags added
-
Re: Programming homework, help needed!
I've edited your post and have added code tags to your posted code with the tag [code] above a code block and [/code] below a code block, but still your code is hard to read as it has no formatting to begin with. Please edit your post above and post formatted code so that we will be able to read it. Also please post any error text the code generates, and indicate some way to us which lines are causing these errors.
- 03-12-2012, 01:16 AM #5
Member
- Join Date
- Mar 2012
- Posts
- 4
- Rep Power
- 0
Re: Programming homework, help needed!
I am sorry as you can see I am new to these forums and not quite sure of the rules. I will post the formatted lines that are giving me errors. All the errors occur in my TestCashier class, as my GetData and Cashier classes have no compile errors as of now.
Here the error shows as "name and price already defined in main(java.lang.String[])Java Code: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); name = GetData.getWord(“Enter name of item”); price = GetData.getDouble(“Enter price of item”); c.add(name, price);
and for c.add(name,price) it says it has not been initialized.
Also for this single line of coding, tendered(amount);
it says it cannot find symbol.
I am confused as to how to put everything working together, if you could point out my mistakes it would be greatly appreciated!
- 03-12-2012, 02:35 AM #6
Member
- Join Date
- Mar 2012
- Posts
- 4
- Rep Power
- 0
Re: Programming homework, help needed!
I'm sorry for double posting, but pleaseeeee could anyone help me? I am in desperate need of some assistance :(
- 03-12-2012, 05:30 AM #7
Member
- Join Date
- Mar 2012
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
First homework and I'm new to Java and new to programming itself, Plz help :(
By Zahara in forum New To JavaReplies: 3Last Post: 02-11-2012, 12:45 AM -
programming homework
By pinkdiamondgail in forum Advanced JavaReplies: 3Last Post: 04-15-2009, 01:10 PM -
programming homework
By pinkdiamondgail in forum Advanced JavaReplies: 2Last Post: 04-14-2009, 11:06 PM -
Help needed for a 40 mark homework due in 1 hour .. plz
By q8ysurgeon in forum New To JavaReplies: 5Last Post: 01-09-2009, 05:07 PM -
Help needed for a 40 mark homework due in 1 hour .. plz
By q8ysurgeon in forum Advanced JavaReplies: 3Last Post: 01-09-2009, 04:09 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks