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: Having Issues Past this

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Having Issues Past this

    As it says, I'm having problems with this code in this exercise. My teacher says its straight forward, but he really hasn't been a reliable source of knowledge.

    I'm not asking for help finishing this exercise (well, at least not ENTIRELY), I'm asking if some kind folks are willing to help these lines make sense to me, because my teachers lessons make about as much sense as reading a book about Philosophy and trying to explain it to a 5 year old...

    I've highlighted the areas and gave them some underline spots instead of the [insert code here] stuff he had there.

    Thanks again in advance to whoever is willing to help.




    // Make it possible to use required packaged code
     
    import [COLOR="Red"] java.util[/COLOR];
    import java.io.*;
    import java.text.*;
     
    // This class defines a program to process orders for a fast food restaurant.
    // ---- Written by: Jon Huhtala
    // --- Modified by: My name
     
    public class Project02 {
     
      // This method begins application processing.
     
      public static void main(String[] args) {
     
        // Variables.
     
        double taxRate;             // For holding the tax rate.
        String reply;               // For holding the user's latest keyboard entry.
        ArrayList quantities;       // For holding the item quantities for the
                                    // customer order.
     
        // These coordinated arrays hold item names and their prices
     
        String[] items = {"Burgers", "Fries", "Drinks"};
        double[] prices = {2.75, 1.50, 1.35};
     
        // If the program did not receive a command line parameter, set the
        // tax rate to .06 (meaning 6%). Otherwise, set the tax rate to the
        // value of the parameter.
     
        if ([COLOR="Red"]_______________[/COLOR] == 0) {
          taxRate = .06;
        }
        else {
          String taxRateAsString =[COLOR="Red"] __________[/COLOR];     // GET PARAMETER VALUE.
          taxRate =[COLOR="Red"] ____________[/COLOR](taxRateAsString); // CONVERT FROM String TO double.
        }
     
        // Loop to process one customer order.
     
        do {
     
          // Display item names and prices.
     
          System.out.println("");
          System.out.println("--------- ITEMS AND PRICES ---------");
          System.out.println("");
     
          // THIS LOOP SHOULD DISPLAY ITEM NAMES AND PRICES IN A FORMAT THAT
          // MATCHES THE SAMPLE OUTPUT SHOWN BELOW.
     
          for (int i = 0; i < [COLOR="Red"]______._____[/COLOR]; i++) { // LIMIT BY SIZE OF items ARRAY.
            System.out.println(" " +[COLOR="Red"] ________ [/COLOR]+ "..." + Utility.moneyFormat([COLOR="Red"]________[/COLOR]));
          }
     
          // Get order data.
     
          System.out.println("");
          System.out.println("------------ YOUR ORDER ------------");
          System.out.println("");
          quantities = new ArrayList();
     
          // THIS LOOP SHOULD PROMPT FOR AND READ THE NUMBER OF EACH ITEM THE
          // CUSTOMER WANTS TO BUY. IT SHOULD MATCH THE FORMAT OF THE SAMPLE
          // OUTPUT SHOWN BELOW.
     
          for (int i = 0; i < [COLOR="Red"]______._____[/COLOR]; i++) { // LIMIT BY SIZE OF items ARRAY.
            System.out.print(" Number of " +[COLOR="Red"] _____________[/COLOR] + ": ");
            reply = Utility.readString();
            quantities.[COLOR="Red"]______________[/COLOR]; // ADD TO THE quantities ArrayList.
          }
     
          // Calculate and display "Payment Due" information.
     
          System.out.println("");
          System.out.println("----------- PAYMENT DUE ------------");
          System.out.println("");
          double subtotal = calculate(prices, quantities);
          System.out.println(" Subtotal: " + Utility.moneyFormat(subtotal));
          double tax = subtotal * taxRate;
          System.out.println(" Tax: " + Utility.moneyFormat(tax) +
                             " at " + [COLOR="Red"]__________[/COLOR]); // SHOW taxRate AS FORMATTED PERCENTAGE.
          double totalDue = subtotal + tax;
          System.out.println(" TOTAL: " + Utility.moneyFormat(totalDue));
     
          // Ask the user if they want to process another order. If they reply with
          // a String whose value is "YES", repeat this loop.
     
          System.out.println("");
          System.out.println("-------------- AGAIN? --------------");
          System.out.println("");
          System.out.print(" Enter YES to do another order: ");
          reply = Utility.readString();
        } while ([COLOR="Red"]____________[/COLOR]); // ACCEPT "YES" IN ANY CASE (LIKE "yes") TO CONTINUE.
      }
     
      // This method can be called to calculate the non-taxable amount due for
      // an order. It receives the array of prices and ArrayList of corresponding
      // quantities as parameters.
     
      public static double calculate([COLOR="Red"]____________, _____________________[/COLOR]) {
        double total = 0;
        for (int i = 0; i < [COLOR="Red"]______._______[/COLOR]; i++) { // LIMIT BY SIZE OF THE ARRAY.
          double price = [COLOR="Red"]_____________________[/COLOR]; // GET THE ITEM'S PRICE.
          int quantity = [COLOR="Red"]_____________________[/COLOR]; // GET CORRESPONDING QUANTITY ORDERED.
          double extendedPrice = price * quantity;
          total += extendedPrice;
        }
        return total;
      }
    }
     
    // This class contains custom methods that support application processing.
    // ----- Written by: Jon Huhtala
     
    class Utility {
      private static BufferedReader kbReader =
        new BufferedReader(new InputStreamReader(System.in));
     
      // This method read a String value from the keyboard.
     
      public static String readString() {
        String result = null;
        while (result == null) {
          try {
            result = kbReader.readLine();
          }
          catch(Exception err) {
            System.out.print("ERROR! Please try again: ");
          }
        }
        return result;
      }
     
      // This method converts a double to a formatted currency String.
      // For example: 1234.56 --> "$1,234.56"
     
      public static String moneyFormat(double amount) {
        return NumberFormat.getCurrencyInstance().format(amount);
      }
     
      // This method converts a double to a formatted percentage String
      // having exactly one decimal place.
      // For example: .075 --> "7.5%"
     
      public static String percentFormat(double amount) {
        NumberFormat nf = NumberFormat.getPercentInstance();
        nf.setMaximumFractionDigits(1);
        nf.setMinimumFractionDigits(1);
        return nf.format(amount);
      }
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Having Issues Past this

    There's a lot of red in there, so its hard to address each and every one. But for each case the comments near them describe exactly what needs to be done, just take it one step at a time. To help you off, you need to check for command line arguments...specified in args[]. Check the length of the array ('.length' returns the length of an array - further down the line remember that ArrayList is an object - different than array, use size() to get its length), and if it is greater than zero use that value to set the tax rate (you have the Utility class to help you do some common things. Hope this helps at least some
    Last edited by copeg; November 13th, 2009 at 09:28 AM.

Similar Threads

  1. Replies: 0
    Last Post: October 2nd, 2009, 10:51 PM
  2. Maven Issues - mvn install
    By Paolo Futre in forum Java Theory & Questions
    Replies: 5
    Last Post: August 26th, 2009, 05:07 AM
  3. Problem with sprite rotation in graphics
    By Katotetu in forum Algorithms & Recursion
    Replies: 0
    Last Post: May 8th, 2009, 07:27 PM