Requirements: N bookstore for "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%
n Depending on the number of volumes purchased and the number of copies, 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 N design algorithm calculates the lowest price for a reader to buy a batch of books. Design ideas: Because buy eight of the time discount is not to buy five the least, but 4+4, so in each is divisible by eight when the need to calculate separately. Source:
ImportJava.util.*;Importjavax.swing.*; Public classHaripoter { Public Static voidMain (string[] args) {//TODO auto-generated Method StubSystem.out.println ("Please enter purchase quantity (this):"); Scanner SCA=NewScanner (system.in); intnum =Sca.nextint (); DoublePrice = 0; System.out.println ("Total Price is:"); if(num%8==0) { price= (NUM/8) *51.2; System.out.println ( Price+ "Yuan"); } if(num%8==1) { price= (NUM/5) *30+8; System.out.println ( Price+ "Yuan"); } if(num%8==2) { price= (NUM/5) *30+15.2; System.out.println ( Price+ "Yuan"); } if(num%8==3) { price= (NUM/5) *30+21.6; System.out.println ( Price+ "Yuan"); } if(num%8==4) { price= (NUM/5) *30+25.6; System.out.println ( Price+ "Yuan"); } if(num%8==5) { price= (NUM/5) *30+30; System.out.println ( Price+ "Yuan"); } if(num%8==6) { price= (NUM/5) *30+38; System.out.println ( Price+ "Yuan"); } if(num%8==7) { price= (NUM/5) *30+45.2; System.out.println ( Price+ "Yuan"); } } }Main
Results:
Software engineering Exercises--buying books