Software engineering Exercises--buying books

Source: Internet
Author: User

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

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.