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

Code Java:

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

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.

Re: Need Help applying discount

could i perhaqps do it with if statements for instance

Code :

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