Title Requirements:
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: This number discount 2--5%, 3--10%, 4--20%, 5--25%.
Design ideas:
According to the actual situation shows that only buy 8 is two 4 of the best, the remaining is 5+x (x<=5) Purchase method, the stock purchase of the book in addition to 10 to take the remainder, the ten parts are the maximum discount buy is 5+5, and the remainder is based on the analysis of the previous purchase.
Test source code:
ImportJava.util.Scanner; Public classClassproject { Public Static voidMain (string[] args) {//TODO auto-generated Method StubSystem.out.println ("Please enter the number of books to buy:"); Scanner SC1=NewScanner (system.in); intnum =Sc1.nextint (); intNum_1=num/10; intNum_2=num%10; Doubleprice=num_1*2*5*8* (1-0.25); if(num_2==0) Price=price+0; if(num_2==1) Price=price+8; if(num_2==2) Price=price+2*8* (1-0.05); if(num_2==3) Price=price+3*8* (1-0.1); if(num_2==4) Price=price+4*8* (1-0.2); if(num_2==5) Price=price+5*8* (1-0.25); if(num_2==6) Price=price+5*8* (1-0.25) +8; if(num_2==7) Price=price+5*8* (1-0.25) +2*8* (1-0.05); if(num_2==8) Price=price+2*4*8* (1-0.2); if(num_2==9) Price=price+5*8* (1-0.25) +4*8* (1-0.2); System.out.println ("Best Price is:" +price+ "Yuan"); }}
Test:
Classroom Practice-Best book price