Untitled

Anonymous
Plain Text
09/20/2025 6:03 AM
1.2 KB
20
Indexable
Never
// Online Java Compiler
// Use this editor to write, compile and run your Java code online
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
     
     Scanner s = new Scanner (System.in);
     
     //Asking the user to enter the total purchase amount
     System.out.print("Enter the total purchase amount: PHP ");
     double totalAmount = s.nextDouble();
     
     //Declaring the variable for final and discount price
     double discount = 0;
     double finalPrice = totalAmount;
     
     //Applying the appropriate discout based on the total amount that has been purchased 
     if (totalAmount > 10000) {
         discount = 15; 
         finalPrice = totalAmount * (1 - 0.15);
     } else if (totalAmount >= 5001) {
         discount = 10;
         finalPrice = totalAmount * (1 - 0.10);
     } else if (totalAmount >= 1000) {
         discount = 5;
         finalPrice = totalAmount * (1 - 0.05);
     }
      // Display the discount and the final price after the discount
        System.out.println("Discount applied: " + discount + "%");
        System.out.println("Final price after discount: PHP " + String.format("%.2f", finalPrice));
    }
}
     
Editor is loading...
Leave a Comment