indigrace's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
2 (0 per day)
Joined:
13-February 13
Profile Views:
83
Last Active:
User is offline Feb 14 2013 01:57 AM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Windows
Favorite Browser:
Who Cares
Favorite Processor:
AMD
Favorite Gaming Platform:
XBox
Your Car:
Who Cares
Dream Kudos:
0
Icon   indigrace has not set their status

Posts I've Made

  1. In Topic: Question with Array Output with my Program

    Posted 13 Feb 2013

    View Postpbl, on 13 February 2013 - 10:38 AM, said:

    A correctly developed Java application should, most of the case, have a single static method and it is the main() method.

    All other method shouldn't be static as they apply to an object of the class

    The main() method should only have a few lines (1-5) where an object of the class is instantiate and after that everything happens in the class methods themselve

    :^:/>/>


    Ok, here is the code that I've been working on all day. Again, please remember I've only been doing Java for 3 weeks so I'm stumbling through some things. The code I posted earlier was my pre-Arrays attempts. The program still compiles and runs correctly but I still can't get it to advance when you choose "n" for another quote so I can't see if the information has been collected by the array. Or if what I'm even saying makes sense.

    import java.text.NumberFormat;
    import java.util.ArrayList;
    import java.util.Scanner;
    
    public class NewClass {
    
         public static void main(String[] args)
        {
            ArrayList<String> code =  new ArrayList<>();
            
            // display a welcome message
            System.out.println("Welcome to the High Octane Quote Calculator");
            System.out.println();
    
            // perform 1 or more calculations
            Scanner sc = new Scanner(System.in);
            String choice = "y";
            while (choice.equalsIgnoreCase("y"))
            {
    
                // get the input from the user
                System.out.println("Please complete the following fields");
                System.out.print("Enter customer type= New or Existing (n/e): ");
                String customerType = sc.next();
                double shirtQuantity = getDoubleWithinRange(sc,
                    "Enter Shirt Quantity: ", 0, 1000);
                int colors = getColorWithinRange(sc,
                    "Enter number of Colors in Design ($20/color): ", 0, 8);
                
                // get the discount percent
                double discountPercent = getDiscountPercent(customerType, shirtQuantity);
    
                // calculate the discount amount and total
                double shirtCost = shirtQuantity * 7;
                double discountAmount = shirtCost * discountPercent;
                double subtotal = shirtCost - discountAmount;
                int setupColor = colors * 20;
                double Total = subtotal + setupColor;
    
                // get the currency and percent formatters
                NumberFormat currency = NumberFormat.getCurrencyInstance();
                NumberFormat percent = NumberFormat.getPercentInstance();
                percent.setMinimumFractionDigits(1);
    
                // format the result as a single string
                String results =
                      "Shirt Cost:\t"
                          + currency.format(shirtCost) + "\n"
                    + "Color Setup Fee:\t"
                          + currency.format(setupColor) + "\n"
                    + "Discount Amount:\t"
                          + currency.format(discountAmount) +  "\n"
                    + "Current Total (includes applicable discounts):\t\t"
                          + currency.format(Total) + "\n";
    
                // save the String in the ArrayList
                code.add(results);
                 // see if the user wants to calculate another quote
                System.out.print("Would you like to quote another project? (y/n): ");
                choice = sc.next();
                System.out.println();
            }   
                // print the results
                System.out.println();
                System.out.println("INITIAL QUOTE");
                System.out.println("Shirt\tCost\tSetup\tFee\t\t\tDiscount\t\t\tTotal");
                System.out.println("------.\t----\t\t\t-----\t\t\t------");
    
           // prints the Strings stored in the ArrayList
               for(int i = 0; i < code.size(); ++i) {
                System.out.println(code.get(i));
            }
        }
         
            
    public static double getDouble(Scanner sc, String prompt)
        {
            boolean isValid = false;
            double d = 0;
            while (isValid == false)
            {
                System.out.print(prompt);
                if (sc.hasNextDouble())
                {
                    d = sc.nextDouble();
                    isValid = true;
                }
                else
                {
                    System.out.println("Error! Invalid decimal value. Try again.");
                }
                sc.nextLine();  // discard any other data entered on the line
            }
            return d;
        }
    
        public static double getDoubleWithinRange(Scanner sc, String prompt,
        double min, double max)
        {
            double d = 0;
            boolean isValid = false;
            while (isValid == false)
            {
                d = getDouble(sc, prompt);
                if (d <= min) {
                    System.out.println(
                        "Error! Number must be greater than " + min + ".");
                }
                else if (d >= max) {
                    System.out.println(
                        "Error! Number must be less than " + max + ".");
                }
                else {
                    isValid = true;
                }
            }
            return d;
        }
    
        public static int getInt(Scanner sc, String prompt)
        {
            boolean isValidInt = false;
            int i = 0;
            while (isValidInt == false)
            {
                System.out.print(prompt);
                if (sc.hasNextInt())
                {
                    i = sc.nextInt();
                    isValidInt = true;
                }
                else
                {
                    System.out.println("Error! Invalid entry. Y/N only. Try again.");
                }
                sc.nextLine();  // discard any other data entered on the line
            }
            return i;
        }
    
        public static int getColorWithinRange(Scanner sc, String prompt,
        int min, int max)
        {
            int i = 0;
            boolean isValid = false;
            while (isValid == false)
            {
                i = getInt(sc, prompt);
                if (i <= min) {
                    System.out.println(
                        "Error! Number must be greater than " + min + ".");
                }
                else if (i >= max) {
                    System.out.println(
                        "Error! Number must be less than " + max + ".");
                }
                else {
                    isValid = true;
                }
            }
            return i;
        }   
            
         public static double calculateTotal(double subtotal, int setupColor){
             double Total;
             { 
                 Total = (subtotal + setupColor);
             }
             return Total;
         }
         
            // a static method that that has two parameters: customer type and subtotal.
        /**
         *
         * @param customerType
         * @param shirtQuantity
         * @return discountPercent
         */
        public static double getDiscountPercent(String customerType, double shirtQuantity) {
               double discountPercent = 0;
               if (customerType != null) {
                if (customerType.equalsIgnoreCase("E"))
                {
                    if (shirtQuantity < 40) {
                        discountPercent = 0;
                    }
                    else if (shirtQuantity >= 40 && shirtQuantity < 100) {
                        discountPercent = .2;
                    }
                    else if (shirtQuantity >= 100) {
                        discountPercent = .3;
                    }
                }
                else if (customerType.equalsIgnoreCase("N"))
                {
                    if (shirtQuantity < 40) {
                        discountPercent = 0.5;
                    }
                    else if (shirtQuantity >= 40 && shirtQuantity < 100) {
                        discountPercent = .25;
                    }
                    else if (shirtQuantity >= 100) {
                        discountPercent = .35;
                    }
                }
            }
     
                return discountPercent;
    }
    }
    
    

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Location:
Scenic Flint, MI
Years Programming:
0

Contact Information

E-mail:
Private
Twitter:
indigrace

Friends

indigrace hasn't added any friends yet.

Comments

indigrace has no profile comments yet. Why not say hello?