Classroom Practice-Best book price

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.