First, title:
N 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 as shown in the number 2, discount 5%; This number 3, discount 10%; Ben 4, Discount 20%; the number 5, discount 25%; will correspond to different discount rule conditions. 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.
Second, the problem-solving ideas:
Through the analysis of 6 books, 7 books, 8 books, 9 books, when the number is 6, 7, 9 o'clock, the cheapest combination is 5+1,5+2,5+4, when this number is 8 o'clock, the cheapest combination is 4+4, so when this number is 13,23,33, it is necessary to separate a 8来 to be the cheapest, So there are two cases: this number divided by five is the remainder of 3 and this number divided by five is the remainder of 3.
Third, the source code:
PackageShopp;ImportJava.util.*; Public classMain { Public Static voidMain (string[] args) {//TODO auto-generated Method Stub intN=0; intN=0; intM=0; Scanner S=NewScanner (system.in); System.out.print ("Please enter the number of the book you want to buy:"); N=S.nextint (); if(n%5==3) {n=n/5; M=n%5; if(n==0) {System.out.println ("The lowest price the reader buys for a batch of books is:" + (3*8*0.9)); } Else{System.out.println ("The lowest price for readers to buy a batch of books is:" + ((n-1) *5*8*0.75+2*4*8*0.8)); } } Else{n=n/5; M=n%5; Switch(m) { Case0:system.out.println ("The lowest price the reader buys a batch of books is:" + (n*5*8*0.75)); Break; Case1:system.out.println ("The lowest price the reader buys a batch of books is:" + (n*5*8*0.75+8)); Break; Case2:system.out.println ("The lowest price the reader buys a batch of books is:" + (n*5*8*0.75+m*8*0.95)); Break; Case4:system.out.println ("The lowest price the reader buys a batch of books is:" + (n*5*8*0.75+m*8*0.9)); Break; Case5:system.out.println ("The lowest price the reader buys a batch of books is:" + (n*5*8*0.75+m*8*0.75)); Break; } } }}
Iv. operation of the program:
V. Personal SUMMARY
The overall feeling of the experiment is better, there are not too many problems, mainly in the use of switch statements, forget to add break.
The design algorithm calculates the lowest price for the reader to buy a batch of books