Online Shopping Discount with Membership
This program checks discount eligibility based on purchase and membership.
Problem Statement
Write a Java program that checks discount eligibility based on purchase amount and membership status.
Source Code
| 1 | public class ShoppingDiscountNested { |
| 2 | public static void main(String[] args) { |
| 3 | double purchase = 2000; |
| 4 | boolean member = true; |
| 5 | if(purchase >= 1500) { |
| 6 | if(member) { |
| 7 | System.out.println("Discount applied - Eduinq"); |
| 8 | } else { |
| 9 | System.out.println("No discount: Not a member - Eduinq"); |
| 10 | } |
| 11 | } else { |
| 12 | System.out.println("No discount: Purchase too low - Eduinq"); |
| 13 | } |
| 14 | } |
| 15 | } |
Program Output
Discount applied - Eduinq
Explanation
The program first checks if purchase amount is at least 1500. If true, it then checks if the customer is a member. Only if both conditions are satisfied, discount is applied. Shows how nested if can handle shopping discount eligibility.