While purchasing certain items, a discount of 10% is offered if the quantity purchased is more than 1000. If quantity and price per item are input through the keyboard, write a Java program to calculate the total expenses.

import java.util.Scanner;

public class Program 
{
    	public static void main( String[] args ) 
    	{
		Scanner reader = new Scanner(System.in);
	
		int qty, dis = 0;
		float rate, expense;

		System.out.print("\nEnter Quantity: ");
		qty = reader.nextInt();

		System.out.print("Enter Rate: ");
		rate = reader.nextFloat();

		if (qty>1000)
			dis = 10;

		expense= (qty*rate) - (qty*rate*dis / 100);
		System.out.print("\nTotal Expenses = Rs." + expense);
    	}
}

Output :
Enter Quantity and Rate: 1020
120

Total Expenses = Rs. 110160.000000



Leave a comment