Friday, October 21, 2011

Electronic Purchase

// An electronic shop has announced the following seasonal discounts on the purchase of certain items.
// a program  to input name, address, amount of purchase and the type of purchase (L for laptop and D for Desktop) by a customer. Compute and print the net amount to be paid by a customer along with his name and address.
// (Hint:   discount = (discount rate/100) * amount of purchase
// Net amount = amount of purchase - discount)
//
// VARIABLE DESCRIPTION:
// NAME = STORES THE NAME OF THE CUSTOMER
// ADDRESS = STORES THE ADDRESS OF THE CUSTOMER
// COST = COST WITHOUT ANY DISCOUNT
// TOTALCOST = IT IS THE TOTAL COST AFTER THE DISCOUNT
// TYPE = IT IS WHETHER A LAPTOP OR DESKTOP COMPUTER
// SAVE = TOTAL CASH SAVED
// NET = NET AMOUNT

import java.io.*;
import java.util.*;

class ELECTRONIC_PURCHASE
{
    private static String name,address;
    private static String type;
    private static int num;
    private static double cost,totalcost,discount,save,net;
    public static void main(String args[])throws IOException
    {
        System.out.println("...............................................................................................................................................");
        System.out.println("");
        System.out.println("              ....................................................................................");
        System.out.println("              .                                   ENTER THE NUMBER OF THE PRODUCTS WHERE :       .");
        System.out.println("              .                                     Laptop                Desktop                .");
        System.out.println("              .              0-25000                0%                          5%               .");                      
        System.out.println("              .          25001-57000                5%                        7.5%               .");                        
        System.out.println("              .         57001-100000              7.5%                         10%               .");                           
        System.out.println("              .     more than 100000               10%                         15%               .");
        System.out.println("              ...................................................................................");
        System.out.println("");
        System.out.println("...............................................................................................................................................");
        System.out.println("");
        InputStreamReader reader=new InputStreamReader(System.in);
        BufferedReader input=new BufferedReader(reader);
      
        System.out.println("ENTER THE NAME OF THE CUSTOMER");
        System.out.print("USER INPUT :");
        name=input.readLine();
        System.out.println("ENTER THE ADDRESS OF THE CUSTOMER");
        System.out.print("USER INPUT :");
        address=input.readLine();
        System.out.println("ENTER THE COST OF THE PRODUCT");
        System.out.print("USER INPUT :");
        try
        {
            cost=Double.parseDouble(input.readLine());
        }
         catch(Exception b)
        {
            System.out.println("");
            System.out.println("\t\tERROR FOUND : YOU HAVE TO ENTER ONLY INTEGERS PLEASE RERUN THE PROGRAM");
            System.exit(0);
        }
        choice();
        if(num==0||num<0)
        {
            System.out.println("                                         THANKYOU FOR YOUR COOPERATION THE PROGRAM WILL NOW EXIT");
            System.exit(0);
        }
    }
   
    private static void choice()throws IOException
    {
        InputStreamReader reader=new InputStreamReader(System.in);
        BufferedReader input=new BufferedReader(reader);
        System.out.println("ENTER WHETHER THE COMPUTER TO BE BOUGHT IS :");
        System.out.println("LAPTOP    TYPE L");
        System.out.println("DESKTOP   TYPE D");
        System.out.print("USER INPUT :");
        type=input.readLine();
       
            if(type.equalsIgnoreCase("L"))
            {
                if(cost<25001)
                {
                     System.out.println("");
                     discount=0;
                     System.out.println("THE DISCOUNT AVAILABLE FOR THIS PRODUCT IS 0%");
                     System.out.println("");
                     totalcost=cost-discount;
                     save=discount;
                     net=cost-discount;
                     System.out.println("");
                     bill();
                }
                else if(cost>25001&&cost<57001)
                {
                     System.out.println("");
                     discount=5/100.0*cost;
                     System.out.println("THE DISCOUNT AVAILABLE FOR THIS PRODUCT IS 5%");
                     System.out.println("");
                     totalcost=cost-discount;
                     save=discount;
                     net=cost-discount;
                     System.out.println("");
                     bill();
                }
                else if(cost<57001&&cost>100001)
                {
                     System.out.println("");
                     discount=7.5/100.0*cost;
                     System.out.println("THE DISCOUNT AVAILABLE FOR THIS PRODUCT IS 7.5%");
                     System.out.println("");
                     totalcost=cost-discount;
                     save=discount;
                     net=cost-discount;
                     System.out.println("");
                     bill();
                }
                else if(cost>100000)
                {
                     System.out.println("");
                     discount=10/100.0*cost;
                     System.out.println("THE DISCOUNT AVAILABLE FOR THIS PRODUCT IS 10%");
                     System.out.println("");
                     totalcost=cost-discount;
                     save=discount;
                     net=cost-discount;
                     System.out.println("");
                     bill();
                }
                else
                {
                    System.out.println("THE PROGRAM WILL TERMINATE");
                   
                }
               
            }
            else if(type.equalsIgnoreCase("D"))
            {
               
                if(cost<25001)
                {
                     System.out.println("");
                     discount=5/100.0*cost;
                     System.out.println("THE DISCOUNT AVAILABLE FOR THIS PRODUCT IS 5%");
                     System.out.println("");
                     totalcost=cost-discount;
                     save=discount;
                     net=cost-discount;
                     System.out.println("");
                     bill();
                }
                else if(cost>25001&&cost<57001)
                {
                     System.out.println("");
                     discount=7.5/100.0*cost;
                     System.out.println("THE DISCOUNT AVAILABLE FOR THIS PRODUCT IS 7.5%");
                     System.out.println("");
                     totalcost=cost-discount;
                     save=discount;
                     net=cost-discount;
                     System.out.println("");
                     bill();
                }
                else if(cost<57001&&cost>100001)
                {
                     System.out.println("");
                     discount=10/100.0*cost;
                     System.out.println("THE DISCOUNT AVAILABLE FOR THIS PRODUCT IS 10%");
                     System.out.println("");
                     totalcost=cost-discount;
                     save=discount;
                     net=cost-discount;
                     System.out.println("");
                     bill();
                }
                else if(cost>100000)
                {
                     System.out.println("");
                     discount=15/100.0*cost;
                     System.out.println("THE DISCOUNT AVAILABLE FOR THIS PRODUCT IS 15%");
                     System.out.println("");
                     totalcost=cost-discount;
                     save=discount;
                     net=cost-discount;
                     System.out.println("");
                     bill();
                }
                else
                {
                    System.out.println("THE PROGRAM WILL TERMINATE");
                   
                }
                  
           
        }
        else
        {
            System.out.println("");
            System.out.println("\t\tERROR FOUND : YOU HAVE TO ENTER ONLY INTEGERS PLEASE RERUN THE PROGRAM");
            System.exit(0);
        }
    }
    private static void bill()
    {
        Date date=new Date();
        System.out.println("...............................................................................................................................................");
        System.out.println("");
        System.out.println("                                       .........................................................");
        System.out.println("                                       .                          "+date+".");
        System.out.println("                                              NAME OF THE CUSTOMER IS:"+name+"                  ");
        System.out.println("                                       .      ADDRESS OF THE CUSTOMER IS:"+address+"            ");
        System.out.println("                                       .      THE ACTUAL COST OF THE PRODUCT IS "+cost+"        ");
        System.out.println("                                       .      TOTAL COST TO BE PAID IS "+totalcost+"            ");                        
        System.out.println("                                       .      TOTAL MONET SAVED IS "+save+"                     ");                           
        System.out.println("                                       .      NET AMOUNT TO BE PAID IS "+net+"                  ");
        System.out.println("                                       .........................................................");
        System.out.println("");
        System.out.println("...............................................................................................................................................");
        System.out.println("");
        System.out.println("                                         THANKYOU FOR YOUR COOPERATION PLEASE COME BACK AGAIN");
    }
}

No comments:

Post a Comment