Personal assignments-Buy books

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:
Discount on this number
2 5%
3 10%
4 20%
5 25%
Depending on the number of volumes purchased and this number, 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.


Design ideas:

1. Enter the number of books to buy x?

2, a=x%8;

3. Define the variable y as the amount of money

4, if a==0,y=x/4*(8*4*0.8)

5, a!=0, make b=x%5, if b=0,c=0;=0b=1,c=8;b= 2,c=15.2;b=3,c=21.6;b=4,c=25.6;

Y= (X/5) *8*0.75+c
7. Output money y

SOURCE program:

1 ImportJava.util.Scanner;2  Public classMinmoney {3 4      Public Static voidMain (string[] args) {5         //TODO Auto-generated method stubs6System.out.println ("Please enter how many books you want to buy");7Scanner input=NewScanner (system.in);8       intx=input.nextint ();9       inta=x%8;//Special 8Ten       Doubley=0.0;// Money One       intB=x%5; A       DoubleC=0; -       if(a==0) -       { they=6.4*x; -       } -       Else -       { +           if(b==0) -           { +C=0; A           } at           Else if(b==1) -           { -C=8; -           } -           Else if(b==2) -           { inc=15.2; -           } to           Else if(b==3) +           { -c=21.6; the           } *           Else $           {Panax Notoginsengc=25.6; -           } they=6*x+C; +       } ASYSTEM.OUT.PRINTLN ("Minimum Cost" +y+ "Yuan")); the     } +  -}

Results Analysis:

Be sure to analyze the discount you want to make.

Personal assignments-Buy 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.