Results 1 to 2 of 2
  1. #1
    james75 is offline Member
    Join Date
    Jul 2012
    Posts
    1
    Rep Power
    0

    Default trouble placing a loop in code

    Below you will find my code for only the sub method:

    Here is my problem: Im am trying to place a loop that will ask for a product and quantity and place in an array until quit is entered. the array will contain the product, quantity and cost. also, a running subtotal is kept for the items placed in the array. I have racking my brain for hours now. I have tried do-while loops, if-else loops, do not have any idea how I could place a for loop in there... Most of the trouble is when I enter quit to stop the loop. It will not stop or if it does, it puts quit into the array when i display contents of array in the main method.

    public static ArrayList<String> calcBill()
    {
    int quantity;
    String input, product = null;
    final double taxRate = 0.08;
    double subTotal = 0.00, tax = 0.00, subTotal2 = 0.00, totalCost = 0.00,
    shoes = 50.00, tShirts = 30.00, shorts = 75.00, caps = 15.00, jackets = 100.00;
    DecimalFormat dollar = new DecimalFormat("#0.00");
    ArrayList<String> merchandise = new ArrayList<String>();


    product = JOptionPane.showInputDialog(null, "Enter merchandise being purchased: ",
    "Total Bill Option", JOptionPane.PLAIN_MESSAGE);

    input = JOptionPane.showInputDialog(null, "Enter quantity of merchandise: ", "Total Bill Option",
    JOptionPane.PLAIN_MESSAGE);
    quantity = Integer.parseInt(input);


    if (product.equalsIgnoreCase("shoes"))
    {
    subTotal = shoes * quantity;
    }
    else if (product.equalsIgnoreCase("tShirts"))
    {
    subTotal = tShirts * quantity;
    }
    else if (product.equalsIgnoreCase("shorts"))
    {
    subTotal = shorts * quantity;
    }
    else if (product.equalsIgnoreCase("caps"))
    {
    subTotal = caps * quantity;
    }
    else if (product.equalsIgnoreCase("jackets"))
    {
    subTotal = jackets * quantity;
    }
    else
    {
    JOptionPane.showMessageDialog(null, "Invalid choice", "Warning Message", JOptionPane.WARNING_MESSAGE);
    }

    merchandise.add(product + " \t\t " + quantity + " \t\t $" + dollar.format(subTotal) + "\n");
    subTotal2 += subTotal;


    tax = subTotal2 * taxRate;
    totalCost = subTotal + tax;


    merchandise.add("Sub-total is: \t\t\t\t\t $" + dollar.format(subTotal2) + "\n");
    merchandise.add("Sales Tax (8.00%): \t\t\t\t $" + dollar.format(tax));
    merchandise.add("Total Bill is: \t\t\t\t\t $" + dollar.format(totalCost) + "\n");

    return merchandise;

    Thanks in advance for ideas and suggestions.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,413
    Rep Power
    20

    Default Re: trouble placing a loop in code

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. For loop trouble
    By 2wyked in forum New To Java
    Replies: 7
    Last Post: 03-27-2011, 05:50 PM
  2. Trouble with for loop
    By subiedude101 in forum New To Java
    Replies: 4
    Last Post: 02-13-2011, 09:27 PM
  3. trouble with loop
    By aamster in forum New To Java
    Replies: 10
    Last Post: 10-16-2009, 09:18 PM
  4. [SOLVED] Trouble with this loop!
    By PureAwesomeness in forum New To Java
    Replies: 35
    Last Post: 02-02-2009, 07:04 PM
  5. Placing java code/html pages on website host
    By Bomber_Will in forum New To Java
    Replies: 8
    Last Post: 11-30-2008, 04:31 PM

Posting Permissions

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