Java Programming on how to compute Discount

In this Java Programming, I used String and float data type to calculate the Discount and Discounted Prize.

The problem is: Write a program to input the costumers name, price of item, and discount rate. Computer and display the discount and discounted prize.

Just see the variable that I used in the code. A very short and effective coding below will discount and discounted prize.

Source Code:
import java.util.*;

public class Discount
{

public static void main (String[]args)
{
String cname;
float I_price,drate,Drate,discount,dprice;

Scanner in= new Scanner (System.in);

System.out.println("Enter Costumers Name:");
cname =in.next();

System.out.println("Enter Price of Item:");
I_price =in.nextFloat();

System.out.println("Enter Discount Rate:");
drate= in.nextFloat();

discount=(I_price*drate/100);
dprice=(I_price-discount);

System.out.println("Costumer Name:"+cname+"\n"+"Discount Rate:"+discount+"\n"+"Discounted Price:"+dprice+"\n");

 }
}

For me, Float is appropriate data type to use in this programming, but you can also use double or int data type. Just only watch your variable carefully to avi od some errors.
Related Posts Plugin for WordPress, Blogger...