Sunday, 16 September 2012

How to apply discount on a item in Java


import java.io.*;

public class q3
{
          public static void main(String args[]) throws Exception
          {
                   InputStreamReader in = new InputStreamReader(System.in);
                  
BufferedReader br = new BufferedReader(in);
                  
System.out.println("1. Laptop");
                  
System.out.println("2. printer");
                  
System.out.print("Enter choice : ");
                  
int ch=Integer.parseInt(br.readLine());
                  
Float dis;
                  
if(ch==1)
                   {
                             dis=0.15f;
                   }
                   else
                             if(ch==2)
                             {
                                      dis=0.10f;
                             }
                             else
                             {
                                      System.out.println("Wrong Input");
                  
                                      dis=0.0f;
                             }
                   System.out.print("Enter price : ");
                  
float price=Float.parseFloat(br.readLine());
                  
float fprice=price-(dis*price);
                  
System.out.println("Price after discount : "+fprice);
          }
}

No comments:

Post a Comment