Apex Program: Senior Citizen Discount Check – Real-time Scenario with Explanation

Scenario: A company wants to check if a customer is eligible for a discount based on age.
Use Case: If the customer’s age is above 60, show “Senior Discount Applicable”.

Apex Program:

Explanation:

  1. public class DiscountChecker {
    • Creating a class named DiscountChecker
    • Real-world use: This class can be used in a retail or healthcare system
  2. public static void checkDiscount(Integer age) {
    • Method that takes customer age as input
    • Integer age – age value passed when method is called
  3. if(age >= 60) {
    • Checking if the customer is 60 or older
    • Condition to verify senior citizen eligibility
  4. System.debug('Senior Discount Applicable');
    • Logs message if condition is true
    • Could be extended later to apply discount on billing
  5. } else {
    • If condition fails (i.e., age < 60), then this block runs
  6. System.debug('No Discount Available');
    • Message when customer is not eligible
  7. } – method and class close

Sample Calls + Output:

Real-Life Usage:

  • Can be used in Billing System of:
    • Medical stores
    • Movie ticket booking
    • Online shopping for seniors

Visit: https://sfdctelugu.in/courses/

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top