Page 1 of 2 12 LastLast
Results 1 to 20 of 21
Like Tree1Likes

Thread: Assistance needed for my homework please

  1. #1
    ShinTheWolf is offline Member
    Join Date
    Jun 2014
    Posts
    11
    Rep Power
    0

    Default Assistance needed for my homework please

    Hello and good afternoon. I am new to this site and was directed here for help. I have this assignment for my class. I did the majority of the code(s). This is the homework assignment and what it is asking

    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.

    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
    }

    -------------------------------------------------------------------------------------------------
    This is what I have so far

    import java.text.NumberFormat;
    import java.text.DecimalFormat;


    public class Cashier
    {
    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;


    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); //(missing body or declared abstract)
    {
    f.format(tendered = amount); //(cannot find variable)
    }


    public void makeChange()
    {
    this.tendered = tendered;
    change = tendered - totalSum;
    change = 100 * change;
    change = Math.round(change);
    change = change / 100;
    dollars = (int)(tendered - totalSum) * 100 / 100;
    pennies = (int)(change * 100) % 100;
    quarters = (int)pennies / 25;
    pennies = (int)pennies % 25;
    dimes = (int)pennies / 10;
    pennies = (int)pennies % 10;
    nickels = (int)pennies / 5;
    pennies = (int)pennies % 5;
    pennies = (int)pennies;
    }

    public String getNames()
    {
    return name;
    }

    public double getPrices()
    {
    return price;
    }
    public double getTotal()
    {
    return totalSum;
    }

    public double getMoney()
    {
    return tendered;
    }

    public double getChange()
    {
    return tendered - totalSum;
    }

    public double getQuantity()
    {
    return numberOfItems;
    }

    public double getAverage()
    {
    return average();
    }

    public double getDollars()
    {
    return dollars;
    }

    public double getQuarters()
    {
    return quarters;
    }

    public double getDimes()
    {
    return dimes;
    }

    public double getNickels()
    {
    return nickels;
    }

    public double getPennies()
    {
    return pennies;
    }
    }

    }

    ------------------------------------------------------------------

    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);

    // Add a two more entries of your own
    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);
    // 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 (Cannot find symbol)

    c.makeChange();

    generateReceipt(c);

    }
    static void generateReceipt(Cashier c)
    {

    String r = "ABC Groceries Shop \n";

    r = r + "Welcome – thanks for stopping, \n";

    DateFormat df = DateFormat.getDateInstance();

    Date d = new Date();

    NumberFormat f = NumberFormat.getCurrencyInstance();

    r = r + "Today is " + df.format(d) + "\n";

    r = r + c.getNames() + "..... " + f.format(c.getPrices()) + "\n" + c.getNames() + "..... " + f.format(c.getPrices()) + "\n" + c.getNames() + "....." + f.format(c.getPrices()) + "\n";

    r = r + "____________________" + "\n";

    r = r + "Total " + f.format(c.getTotal()) + "\n\n";

    r = r + "Amount tendered " + f.format(c.getMoney()) + "\n";

    r = r + "The change is " + f.format(c.getChange()) + "\n";

    r = r + "There were " + c.getQuantity() + " items" + "\n";
    r = r + "The average price is " + f.format(c.getAverage()) + "\n\n";

    r = r + "The change includes :" + "\n";

    r = r + c.getDollars() + " dollars" + "\n" + c.getQuarters()+ " quarters" + "\n" + c.getDimes()+ " dimes" + "\n" + c.getNickels()+ " nickels" + "\n" + c.getPennies() + " cents";

    JTextArea text = new JTextArea(r,15, 25);

    JScrollPane pane = new JScrollPane(text);

    JOptionPane.showMessageDialog(null,pane, "Your bill", JOptionPane.INFORMATION_MESSAGE);

    }
    }


    What I have problem with is the lines in Bold formatting.
    Last edited by ShinTheWolf; 06-25-2014 at 08:33 PM.

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,076
    Rep Power
    4

    Default Re: Assistance needed for my homework please

    You never tell us what the problem is. Error? Not the desired result? "Not working" doesn't cut it.

    Here's one of your classmate's versions: Unsure on how to write method statement
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    ShinTheWolf is offline Member
    Join Date
    Jun 2014
    Posts
    11
    Rep Power
    0

    Default Re: Assistance needed for my homework please

    Quote Originally Posted by SurfMan View Post
    You never tell us what the problem is. Error? Not the desired result? "Not working" doesn't cut it.

    Here's one of your classmate's versions: Unsure on how to write method statement
    Where I have the problem is this line in the class Cashier.

    public void tendered(double amount); //(missing body or declared abstract)
    {
    f.format(tendered = amount); //(cannot find variable)
    }
    It tells me it has a problem finding a declared abstract as well as being unable to find a variable.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,346
    Rep Power
    6

    Default Re: Assistance needed for my homework please

    Java Code:
    public void tendered(double amount); //  <----- you don't notice anything here which should not be there?
    {
    Perhaps when I change the formatting of the code to what is widely accepted, you see it:

    Java Code:
    public void tendered(double amount); {
    }
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,076
    Rep Power
    4

    Default Re: Assistance needed for my homework please

    If you don't know that you can't put a semicolon there in the first place, then he will probably not notice it. (Now *that* was a hint eh? :))
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,346
    Rep Power
    6

    Default Re: Assistance needed for my homework please

    You're so subtle ;)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,016
    Rep Power
    6

    Default Re: Assistance needed for my homework please

    Well the OP must have some clue about method syntax. That was the only one that had an improperly placed semi-colon.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  8. #8
    ShinTheWolf is offline Member
    Join Date
    Jun 2014
    Posts
    11
    Rep Power
    0

    Default Re: Assistance needed for my homework please

    how do i bring up Java code like you just did, and i have the open bracket

    public void tendered(double amount)
    {

    but my mistake was the semicolon after (double amount)

  9. #9
    ShinTheWolf is offline Member
    Join Date
    Jun 2014
    Posts
    11
    Rep Power
    0

    Default Re: Assistance needed for my homework please

    thank you Jim. As soon as I realized I had a misplaced semicolon, the program compiled. I still have a small issue. When it prints on the JOption, instead of giving me the name of the items, it just says null 0.00

  10. #10
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,016
    Rep Power
    6

    Default Re: Assistance needed for my homework please

    Uh, you're thanking the wrong person. It was Gimbal2 who pointed it out. But he already knows you appreciate his help.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  11. #11
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,016
    Rep Power
    6

    Default Re: Assistance needed for my homework please

    Quote Originally Posted by ShinTheWolf View Post
    how do i bring up Java code like you just did
    I presume you mean the formatted code. Placed your code between code tags . The easiest way is to
    go to the advanced editor, highlight your code, and then click on the hash(#) icon.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  12. #12
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,346
    Rep Power
    6

    Default Re: Assistance needed for my homework please

    Quote Originally Posted by ShinTheWolf View Post
    how do i bring up Java code like you just did
    This will help you out to learn the tricks of this forum: Guide For New Members
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  13. #13
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,076
    Rep Power
    4

    Default Re: Assistance needed for my homework please

    Quote Originally Posted by gimbal2 View Post
    This will help you out to learn the tricks of this forum: Guide For New Members
    Funny how the creator of that guide uses an image to display the raw code tags :) instead of using the [noparse] tags.

    gimbal2 likes this.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  14. #14
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,346
    Rep Power
    6

    Default Re: Assistance needed for my homework please

    Well now I've learned to use the noparse tag too!
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  15. #15
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,016
    Rep Power
    6

    Default Re: Assistance needed for my homework please

    Yeah! I started out using the noparse tag until someone showed me an easier way. I just switch to source mode in the advanced editor and click on the Bold tag inside the left bracket of each code tag. It is an empty Bold tag but if tends to interrupt the formatter, only showing the code tags. Of course, I am always open to other suggestions.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  16. #16
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,076
    Rep Power
    4

    Default Re: Assistance needed for my homework please

    Quote Originally Posted by jim829 View Post
    Yeah! I started out using the noparse tag until someone showed me an easier way. I just switch to source mode in the advanced editor and click on the Bold tag inside the left bracket of each code tag. It is an empty Bold tag but if tends to interrupt the formatter, only showing the code tags. Of course, I am always open to other suggestions.

    Regards,
    Jim
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  17. #17
    ShinTheWolf is offline Member
    Join Date
    Jun 2014
    Posts
    11
    Rep Power
    0

    Default Re: Assistance needed for my homework please

    Thanks to all of you for your help.

  18. #18
    ShinTheWolf is offline Member
    Join Date
    Jun 2014
    Posts
    11
    Rep Power
    0

    Default Re: Assistance needed for my homework please

    Java Code:
        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);
    I am still getting some problems with compiling. For some reason it is unable to find the symbol. This is what it tells me. I don't know what I am doing wrong.

    cannot find symbol
    symbol: method add(String, double)

    This is what it says on the lines of c.add(name, price);

  19. #19
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,225
    Rep Power
    20

    Default Re: Assistance needed for my homework please

    Java is case sensitive.
    Your Cashier class does not have a method 'add'.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  20. #20
    ShinTheWolf is offline Member
    Join Date
    Jun 2014
    Posts
    11
    Rep Power
    0

    Default Re: Assistance needed for my homework please

    When I capitalize it, it works but the test class that I am giving that had the method was lowercase. Unless I'm missing something I don't even know where to begin

Page 1 of 2 12 LastLast

Similar Threads

  1. Inventory Program Part 3 assistance needed
    By bwissman in forum New To Java
    Replies: 4
    Last Post: 02-06-2014, 05:47 PM
  2. Assistance with homework assignment?
    By compscistudent1 in forum New To Java
    Replies: 13
    Last Post: 11-16-2012, 07:50 AM
  3. assistance needed
    By teardrop3903 in forum New To Java
    Replies: 5
    Last Post: 04-18-2011, 04:30 AM
  4. Assistance needed ASAP: Postpix program
    By Debonairj in forum New To Java
    Replies: 18
    Last Post: 07-27-2010, 02:37 PM
  5. Ascii To URL Assistance Needed
    By Sean_J in forum New To Java
    Replies: 2
    Last Post: 03-10-2010, 05:35 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
  •