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 3 of 3

Thread: Need Help applying discount

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Location
    Ballarat, Australia
    Posts
    3
    My Mood
    Confused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Need Help applying discount

    hey community, I'm working on the final component of my assignment and cant figure out how to do a calculation in regards to applying discounts. For my assignment I need to apply a 10% discount on each unit brought in groups of 5. So for example If a purchase was made for 17 DVD-RW+ drives which have a unit price of $30.00 each, then the multi buy discount would apply to the first 15 items (3 groups of 5) and the discount calculation would be: so 10% of $30.00 is $3 X $15 which is a $45.00 discount, but I cant figure out how to program it, i need the discount value to be displayed on the screen, my code so far is

    if (menuChoice == 'C' || menuChoice == 'c') {
     
                    // Product and price information entry
                    System.out.println("Welcome to Tabular sales summary");
                    System.out.println();
     
                    System.out.print( " Please enter product code : ");
                    productCode = scanner.nextLine();
                    System.out.println();
     
                    System.out.print("Enter product description : ");
                    productDescription = scanner.nextLine();
                    System.out.println();
     
                    System.out.print("Please enter unit price : ");
                    unitPrice = scanner.nextDouble();
                    System.out.println();
     
                    System.out.print("Please enter ammount of units purchased : ");
                    quantityPurchased = scanner.nextInt();
                    System.out.println();
     
                    System.out.print("Salesperson : ");
                    salesPerson = charInput.readLine();
                    System.out.println();
     
                    //Layout of recept
                    System.out.print( "Prod. code    ");
                    System.out.print("Product Description                ");
                    System.out.print("Unit Price         ");
                    System.out.print("Qty      ");
                    System.out.println("Total");
     
                    System.out.print("-----------  ");
                    System.out.print("-------------------------          ");
                    System.out.print("-------------      ");
                    System.out.print("------    ");
                    System.out.println("------");
     
                    //Calculations for display
                    subTotal = unitPrice * quantityPurchased;
     
     
     
                 }

    If anyone could help me I would be very thankful


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Need Help applying discount

    When coming up with an algorithm, you have to take apart things that are "automatic" in your head. How did you figure out the discount in your example? Pretend you have a friend who has no idea how to do this- write out instructions that he could follow to accomplish the goal. When you have that written out, you'll have an algorithm that should be pretty easy to translate to code.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Mar 2011
    Location
    Ballarat, Australia
    Posts
    3
    My Mood
    Confused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need Help applying discount

    could i perhaqps do it with if statements for instance

    if (quantityPurchased >= 5 && quantityPurchased <=9)
     
    additionalDiscount = (unitPrice * 5) / 100 * 10;   
     System.out.println(addiltionalDiscount);

    and if so then its going to take alot of if statements. I know the formula for working out percentages i just cant figure out how to write the algorithm code as i am new to java and cant find the information in our text book nor in the lecture notes

Similar Threads

  1. Applying a MIDI instrument change to a Track
    By AnkleSpankle in forum Java Theory & Questions
    Replies: 3
    Last Post: January 23rd, 2011, 03:34 PM

Tags for this Thread