Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Totally stuck on this assignment

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Totally stuck on this assignment

    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.
    Last edited by helloworld922; March 9th, 2010 at 11:59 PM.


  2. #2
    Junior Member
    Join Date
    Mar 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Totally stuck on this assignment

    Quote Originally Posted by Sgiahatch View Post
    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.

    hope it worked out for you!

Similar Threads

  1. Replies: 1
    Last Post: February 22nd, 2010, 08:20 AM
  2. Help I'm stuck on code.
    By GreenM in forum Loops & Control Statements
    Replies: 3
    Last Post: January 29th, 2010, 09:27 PM
  3. I'm stuck
    By iank in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 5th, 2009, 10:21 AM
  4. Problem while programming a simple game of Car moving on a road
    By rojroj in forum Java Theory & Questions
    Replies: 3
    Last Post: April 2nd, 2009, 10:24 AM
  5. stuck on this program can any one help me
    By clive in forum AWT / Java Swing
    Replies: 2
    Last Post: March 10th, 2009, 05:54 PM