write a program in Java language to enter amount of purchase and print the amount payable If the shopkeeper gives a discount of 50% + 40%............plz provide me with the answer .......
Answers
Successive Discount - Java
We need to take User Input. For that, we can either use the BufferedReader or the Scanner. Here, we take Scanner.
So, we import the java.util.Scanner and create a Scanner object. We ask user for input of Amount of Purchase, and store it in a double type variable, which we here name as purchaseAmount.
We choose the double data type to account for fractional values in calculation. Also, double is more accurate and wide ranged than float.
First, we have to give 50% discount. We subtract 50% of purchaseAmount to get intermediate payableAmount.
But, now we are giving an additional 40% discount over this. So, we subtract 40% of the intermediate payableAmount to get the final payableAmount.
And finally we display the amount to be paid.
import java.util.Scanner; //Importing Scanner
public class Discount //Creating Class
{
public static void main(String[] args) //The main function
{
//Create Scanner Object
Scanner scr = new Scanner(System.in);
//Take User Input for Amount of Purchase
System.out.print("Enter Amount of Purchase: ");
double purchaseAmount = scr.nextDouble();
//First Discount is 50%
double payableAmount = purchaseAmount - (0.50*purchaseAmount);
//Second Discount is 40%
//Subtract to get the Final Payable Amount
payableAmount = payableAmount - (0.40*payableAmount);
//Display Payable Amount
System.out.println("Payable Amount: "+payableAmount);
}
}