A company applies a discount based on the price of the order

A company applies a discount based on the price of the order. If the order is over $50, the discount is 5%. If the order is over $100, the discount is 10%. Otherwise, there is no discount. Write a sequence of if statements to get the discounted price of the order.

Solution

import java.util.Scanner;

public class Discount {

   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println(\"Enter the total price\");
       double price = sc.nextDouble();
       double discountedPrice = getDiscountedPrice(price);
       System.out.println(\"Discounted price of the order is : \"+discountedPrice);

   }

   private static double getDiscountedPrice(double price) {
      
       double discountedPrice = 0.0 ;
       // required if else conditions ANS of question
       if(price > 100){
           discountedPrice = price - (price * 0.10);
       }
       if(price > 50 && price <= 100){
           discountedPrice = price - (price * 0.05);
       }
       if(price <= 50 ){
           discountedPrice = price;
          
       }
      
       // ans using if else statements
       /*if(price > 100){
           discountedPrice = price - (price * 0.10);
       }else if(price > 50){
           discountedPrice = price - (price * 0.05);
       }else{
           discountedPrice = price;
          
       }*/
       return discountedPrice;
   }

}

 A company applies a discount based on the price of the order. If the order is over $50, the discount is 5%. If the order is over $100, the discount is 10%. Oth

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site