A shopkeeper offers 30% discount on purchasing articles whereas the other shopkeeper offers two successive discounts 20% and 10% for purchasing the same articles. write a program in java to compute and display which is a better offer for the customer. take the price of an article as input. PLEASE GIVE ANSWER IN BUFFERED CLASS
Answers
Answered by
22
import java.io.*;
class discount
{
public static void main( )throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in))
int price;
double amt1=0.0,amt2=0.0;
System.out.println("Enter price of entity");
price=Integer.parseInt(br.readLine( ));
amt1=price -(30*price)/100.0;
amt2=price-(20*price)/100.0;
amt2=amt2-(10*amt2)/100.0;
if(amt2>amt1)
System.out.println("Shopkeeper 1");
else if(amt2<amt1)
System.out.println("Shopkeeper 2");
else
System.out.println("Both are equal");
}
}
class discount
{
public static void main( )throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in))
int price;
double amt1=0.0,amt2=0.0;
System.out.println("Enter price of entity");
price=Integer.parseInt(br.readLine( ));
amt1=price -(30*price)/100.0;
amt2=price-(20*price)/100.0;
amt2=amt2-(10*amt2)/100.0;
if(amt2>amt1)
System.out.println("Shopkeeper 1");
else if(amt2<amt1)
System.out.println("Shopkeeper 2");
else
System.out.println("Both are equal");
}
}
Answered by
5
import java.io.*;
class Successive{
public static void main(String args[])throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Price: ");
double price = Double.parseDouble(br.readLine());
double discount = 30.0 / 100 * price;
double amount1 = price - discount;
double discount1 = 20.0 / 100 * price;
double amount2 = price - discount1;
double discount2 = 10.0 / 100 * amount2;
amount2 = amount2 - discount2;
System.out.println("Amount 1: " + amount1);
System.out.println("Amount 2: " + amount2);
}
}
Similar questions