Java Program of count Discount Rate

Question:

Water4U is the leading brand of packaged drinking water. The management of Water4U plans to expand the business. So, they decide to give a grand discount on two types of Bottles – 500 ml and 300ml. Discount is given based on the number of cases (bulk purchase) ordered by the distributor for the given condition. Write a Java program to calculate the total price for the distributor based on the discount if applicable

Bottle Size (in ml)Per Bottle Cost(in Rupees)Discount Rate(in percentage)
500105% if total bottle count <=25
5001010% if total bottle count > 25
30062% if total bottle count <= 25
30064% if total bottle count > 25

Note: Bottle size can be either 300 ml or 500 ml. If not display “<size> ml is not avaiable”.

Sample Input 1:

Enter the distributor name

Raghul

Mobile number

9876543210

Bottle size (in ml)

500

No of bottles required

26

Code:

Main.java

import java.util.Scanner;

public class discount_rate {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the distributor name");
        String name = sc.nextLine();
        System.out.println("Mobile number");
        String num = sc.nextLine();
        System.out.println("Bottle size (in ml)");
        int size = sc.nextInt();
        System.out.println("No of bottles required");
        float b = sc.nextFloat();

        if(size<300 || size>500){
            System.out.println(size+" ml is not available");
        }
        else if(size == 500 && b <= 25){
            float c = b*10;
            System.out.println("Total price to be paid by the distributor is "+(c*0.95));
        }
        else if(size == 500 && b>25){
            float c = b*10;
            System.out.println("Total price to be paid by the distributor is "+(c*0.90));
        }
        else if(size == 300 && b<=25){
            float c = b*6;
            System.out.println("Total price to be paid by the distributor is "+(c*0.98));
        }
        else if(size == 300 && b>25){
            float c = b*6;
            System.out.println("Total price to be paid by the distributor is "+(c*0.96));
        }
        else{
            System.out.println("Invalid input");
        }
    }
}

Output:

Enter the distributor name
rahul
Mobile number
9876543210
Bottle size (in ml)
500
No of bottles required
26
Total price to be paid by the distributor is 234.0

Recommended:

Leave a Comment

Your email address will not be published. Required fields are marked *

x