Sales Discount

mail@pastecode.io avatar
unknown
java
2 years ago
1.8 kB
7
Indexable
Never
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.activity;

import java.util.Scanner;

/**
 *
 * @author DEVFINITY
 */
public class SalesDiscount {
    private String productName;
    private double price;
    private double discount;
    private double netPrice;
    
    public SalesDiscount() {       
        Scanner input = new Scanner(System.in);
        
        System.out.print("\nEnter Product: ");
        productName = input.nextLine();
        
        System.out.print("\nEnter Price: ");
        price = Double.parseDouble(input.nextLine());
        
        if(price < 0) {
            System.out.println("Invalid Price");
            return;
        }
        
        if(price >= 0 && price <= 10000) {
            discount = price * 0;
        }
        else if(price >= 10001 && price <= 20000) {
            discount = price * 0.05; // 5% = 0.05
        }
        else if(price >= 20001 && price <= 50000) {
            discount = price * 0.1; // 10% = 0.1
        }
        else if(price >= 50001 && price <= 100000) {
            discount = price * 0.15; // 15% = 0.1
        }
        else {
            discount = price * 0.2; // 20% = 0.2
        }
        
        netPrice = price - discount;
        
        System.out.format("Price of %s is %.2f\n", productName, price);
        System.out.format("Discount is %.2f\n", discount);
        System.out.format("Net Price is %.2f\n", netPrice);
    }
    
    public static void main(String...args) {
        SalesDiscount salesDiscount = new SalesDiscount();
    }
}