Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default 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.

    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
    }
    }
    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 – 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 helpful
    Last edited by Fubarable; 03-11-2012 at 08:07 PM. Reason: code tags added

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Programming homework, help needed!

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

  3. #3
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default Re: Programming homework, help needed!

    Quote Originally Posted by Fubarable View Post
    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.
    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";
    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);
    }
    }
    If you can please point out what I am doing wrong it would help alot thank you!
    Last edited by Fubarable; 03-12-2012 at 12:29 AM. Reason: code tags added

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Programming homework, help needed!

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

  5. #5
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default Re: Programming homework, help needed!

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

    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);
    Here the error shows as "name and price already defined in main(java.lang.String[])
    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!

  6. #6
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default 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 :(

  7. #7
    waiheng1986 is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default Re: Programming homework, help needed!

    your cashier's class constructor should be

    //initialize the value for name and price but not point back the global variable back to itself.
    this.name = "";
    this.price = ''";
    price = 0;
    this.s = "";

    change it and try it again.

Similar Threads

  1. Replies: 3
    Last Post: 02-11-2012, 01:45 AM
  2. programming homework
    By pinkdiamondgail in forum Advanced Java
    Replies: 3
    Last Post: 04-15-2009, 02:10 PM
  3. programming homework
    By pinkdiamondgail in forum Advanced Java
    Replies: 2
    Last Post: 04-15-2009, 12:06 AM
  4. Help needed for a 40 mark homework due in 1 hour .. plz
    By q8ysurgeon in forum New To Java
    Replies: 5
    Last Post: 01-09-2009, 06:07 PM
  5. Help needed for a 40 mark homework due in 1 hour .. plz
    By q8ysurgeon in forum Advanced Java
    Replies: 3
    Last Post: 01-09-2009, 05:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •