Header Ads

A departmental store offers following discounts to customers based on purchase made by them. Write a program to print the bill showing all particulars

At the end, he should print.

******* Thank You *******
    Purchase Amount              Rate of Discount
1. upto 5000                          Nil
2. 5001 to 12000                   3% of Purchase
3. 12001 to 22000                 7% of Purchase
4. Above 22000                     10% of Purchase

Code :

package com.StepTowardsCoding;

import java.util.Scanner;

public class store {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

System.out.print("Enter Purchase Amount : ");
double pa = sc.nextDouble();

double dis = 0;
if (pa<=5000){
dis+=0;
}
else if (pa<=12000){
dis+=0.03*pa;
}
else if (pa<=22000){
dis+=0.07*pa;
}
else{
dis+=0.1*pa;
}
double bill = pa-dis;
System.out.println("Purchase Amount \tRs. "+pa);
System.out.println("Discount \tRs. "+dis);
System.out.println("Billing Amount \tRs. "+bill);
System.out.println("******* Thank You *******");
}
}

Output :

Enter Purchase Amount : 45000
Purchase Amount  Rs. 45000.0
Discount                        Rs. 4500.0
Billing Amount       Rs. 40500.0
******* Thank You *******

Explanation :

This is a simple program which is just going to print bill after discount. Departmental Store Program will be efficient if it is able to store stock information, print bill with items purchased and all other things which a departmental store program can do.
Step Towards Coding deal with basic programming problems so here it is,
this program takes Purchased amount as input, calculate discount and print the output

Post a Comment

2 Comments

  1. import java.util.*;
    public class prog{
    public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter your purchase amount");
    double amt=sc.nextDouble();
    double discount=0;
    if(amt<=5000){
    discount=0;

    }
    else if(amt>=5001&&amt<=12000){
    discount+=(3/100)*amt;

    }
    else if(amt>=12001&&amt<=22000){
    discount+=(7/100)*amt;

    }
    else if(amt>22000){
    discount+=(10/100)*amt;
    }
    double billingamt = amt-discount;
    System.out.println("Your purchase amount is "+amt);
    System.out.println("You got a discount of "+discount);
    System.out.println("Your billing amount is "+billingamt);
    }
    }

    please tell me mistake Discount is coming zero.

    ReplyDelete
    Replies
    1. Sorry for the late reply....
      your program is correct, but you have to use floating point number while assigning discount rate
      For Example : use 0.03 instead of 3/100

      Correct Code:
      import java.util.*;
      public class prog {
      public static void main(String[] args) {
      Scanner sc=new Scanner(System.in);
      System.out.println("Enter your purchase amount");
      double amt=sc.nextDouble();
      double discount=0;
      if(amt<=5000){
      discount=0;

      }
      else if(amt>=5001&&amt<=12000){
      discount+=(0.03)*amt;

      }
      else if(amt>=12001&&amt<=22000){
      discount+=(0.07)*amt;

      }
      else if(amt>22000){
      discount+=(0.1)*amt;
      }
      double billingamt = amt-discount;
      System.out.println("Your purchase amount is "+amt);
      System.out.println("You got a discount of "+discount);
      System.out.println("Your billing amount is "+billingamt);
      }
      }

      Delete

Ask Your Queries in the comments