Bookstore for the "Harry Potter" series of books for promotional activities, a total of 5 volumes, with numbers 0, 1, 2, 3, 4, a single volume of 8 yuan, the specific discount is as follows:
Discount on this number
2 5%
3 10%
4 20%
5 25%
Depending on the number of volumes purchased and this number, different discount rules will be applicable. The singular book only corresponds to one discount rule, for example, two volume 1, one volume 2, you can enjoy 5% discount, another volume does not enjoy the discount.
The design algorithm calculates the lowest price for the reader to buy a batch of books.
[Design idea]:
First, according to the discount method to find the book price law, the purchase of 8 books, to buy four of the method is the most advantageous. Therefore, the number of purchases can be taken to 10 of the remainder by using the switch statement to classify, the divisor multiplied by the purchase of two five of the way the lowest price, and finally add up to the lowest price.
[Code Implementation]:
Import Java.util.scanner;public class Harrypotter {public static void main (String args[]) {Scanner sc = new Scanner (System. in); System.out.println ("Please enter the number of books to be purchased:"); int numbers = Sc.nextint (); float money=0.0f;int A=0,b=0;switch (number%10) {case 0: Break Case 1:money+=8; Break Case 2:money+=15.2; Break Case 3:money+=21.6; Break Case 4:money+=25.6; Break Case 5:money+=30; Break Case 6:money+=38; Break Case 7:money+=45.2; Break Case 8:money+=51.2; Break Case 9:money+=55.6; break;} money+=60* (NUMBER/10); SYSTEM.OUT.PRINTLN ("Purchase" +number+ "book Lowest Price:" +money);}}
[Implementation]:
Software Engineering-class assignments (minimum purchase price)