Unit 3 Boolean - Homework

Homework: Membership Recommendation System

Problem Overview

You are building a membership recommendation system for a fictional company called “Prime Club.” This system will suggest the most suitable membership tier (or tiers) for a user based on their age, annual income, student status, and employment type. There are 4 types of memberships:

Membership Types

  1. Basic Membership:
    • Requirements:
      • Age ≥ 18
      • Annual income ≥ $20,000
  2. Premium Membership:
    • Requirements:
      • Age ≥ 25
      • Annual income ≥ $50,000
  3. Student Discount:
    • Requirements:
      • Must be a student.
  4. Senior Discount:
    • Requirements:
      • Age ≥ 65

Task Description

Using conditional statements, Boolean expressions, and comparison techniques you’ve learned, write a Java program that:

  1. Prompts the user to input the following:
    • Age (as an integer)
    • Annual income (as a double)
    • Student status (yes or no)
    • Employment type (full-time, part-time, unemployed)
  2. Based on these inputs, your program should print out all membership tiers and discounts the user qualifies for. If the user does not qualify for any membership or discount, the program should print:
    “You do not qualify for any memberships or discounts.”

Additional Challenge

Add a final recommendation where your program prioritizes the “best” membership for the user if they qualify for multiple memberships (use an else-if structure).

The best membership should be decided based on the following priorities:

  1. Premium Membership (highest priority)
  2. Senior Discount
  3. Student Discount
  4. Basic Membership (lowest priority)
Hints (click to reveal) 1. **Input Validation:** - Ensure that age is a positive integer, and annual income is a positive double. - Student status input should be case-insensitive ("yes" or "no"). - Employment type should be one of: "full-time", "part-time", or "unemployed." 2. **Conditions to Consider:** - Use `if-else` statements to check for membership qualifications. - Remember to handle multiple conditions where a user qualifies for more than one membership. 3. **Recommendation Logic:** - Use `else-if` statements to prioritize the memberships based on the provided hierarchy.

Constraints

  • Age must be a positive integer.
  • Annual income must be a positive double.
  • Student status should only accept “yes” or “no” (case-insensitive).
  • Employment type should be one of: “full-time”, “part-time”, or “unemployed.”
import java.util.Scanner; 

Scanner input = new Scanner(System.in);

System.out.println("Enter age");
Integer age = Integer.parseInt(input.nextLine());
System.out.println("Age entered: " + age);

System.out.println("Enter income");
Double income = Double.parseDouble(input.nextLine());
System.out.println("Income entered: " + income);

System.out.println("Enter student status [y/n]: ");
Boolean student = (input.nextLine() == "y") ? true : false;
System.out.println("Student status entered: " + student);

System.out.println("Enter employment status [f/u/p]:");
String es = input.nextLine();
System.out.println("Income entered: " + es);

String[] discounts = new String[4];

if (age > 17 && income > 1999.99) {
    System.out.println("Eligible for Basic Membership");
    discounts[3] = "Basic Membership";
}
if (age > 24 && income > 4999.99) {
    System.out.println("Eligible for Premium Membership");
    discounts[0] = "Premium Membership";
}
if (student) {
    System.out.println("Eligible for Student Discount");
    discounts[1] = "Student Discount";
}
if (age > 64) {
    System.out.println("Eligible for Senior Discount");
    discounts[2] = "Senior Discount";
}

for (int i=0;i<4;i++) {
    if (discounts[i] != null) {
        break;
    }
    if (i == 3) {
        System.out.println("You do not qualify for any memberships or discounts");
    }
}

for (int j=0;j<4;j++) {
    if (discounts[j] != null) {
        System.out.println("Best discount/membership: " + discounts[j]);
        break;
    }
}
Enter age


Age entered: 1000
Enter income
Income entered: -20.0
Enter student status [y/n]: 
Student status entered: false
Enter employment status [f/u/p]:
Income entered: f
Eligible for Senior Discount
Best discount/membership: Senior Discount