3.1: Boolean Expressions | 3.2: If Control Flow | 3.3: If Else | 3.4: Else If | 3.5: Compound Booleans | 3.6: Equivalent Booleans | 3.7: Comparing Objects | 3.8: Homework |
Unit 3 Boolean - Homework
Unit 3 Team Teach
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
- Basic Membership:
- Requirements:
- Age ≥ 18
- Annual income ≥ $20,000
- Requirements:
- Premium Membership:
- Requirements:
- Age ≥ 25
- Annual income ≥ $50,000
- Requirements:
- Student Discount:
- Requirements:
- Must be a student.
- Requirements:
- Senior Discount:
- Requirements:
- Age ≥ 65
- Requirements:
Task Description
Using conditional statements, Boolean expressions, and comparison techniques you’ve learned, write a Java program that:
- 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)
- 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:
- Premium Membership (highest priority)
- Senior Discount
- Student Discount
- 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.”
Senior Discount:
Requirements: Age ≥ 65 Task Description: Using conditional statements, Boolean expressions, and comparison techniques you’ve learned, write a Java program that:
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) 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 out: “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: Premium Membership (highest priority) Senior Discount Student Discount Basic Membership (lowest priority) 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;
public class PrimeClubMembership {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your age: ");
int age = scanner.nextInt();
if (age < 0) {
System.out.println("Age must be a positive integer.");
return;
}
System.out.println("Enter your annual income: ");
double income = scanner.nextDouble();
if (income < 0) {
System.out.println("Annual income must be a positive number.");
return;
}
System.out.println("Are you a student? (yes/no): ");
String studentStatus = scanner.next().toLowerCase();
if (!studentStatus.equals("yes") && !studentStatus.equals("no")) {
System.out.println("Invalid input for student status. Please enter 'yes' or 'no'.");
return;
}
boolean isStudent = studentStatus.equals("yes");
System.out.println("What is your employment type? (full-time, part-time, unemployed): ");
String employmentType = scanner.next().toLowerCase();
if (!employmentType.equals("full-time") && !employmentType.equals("part-time") && !employmentType.equals("unemployed")) {
System.out.println("Invalid employment type. Please enter 'full-time', 'part-time', or 'unemployed'.");
return;
}
boolean qualifiesBasic = age >= 18 && income >= 20000;
boolean qualifiesPremium = age >= 25 && income >= 50000;
boolean qualifiesStudent = isStudent;
boolean qualifiesSenior = age >= 65;
System.out.println("\nMemberships you qualify for:");
if (qualifiesBasic) {
System.out.println("- Basic Membership");
}
if (qualifiesPremium) {
System.out.println("- Premium Membership");
}
if (qualifiesStudent) {
System.out.println("- Student Discount");
}
if (qualifiesSenior) {
System.out.println("- Senior Discount");
}
if (!qualifiesBasic && !qualifiesPremium && !qualifiesStudent && !qualifiesSenior) {
System.out.println("You do not qualify for any memberships or discounts.");
}
if (qualifiesPremium) {
System.out.println("\nRecommended membership: Premium Membership");
} else if (qualifiesSenior) {
System.out.println("\nRecommended membership: Senior Discount");
} else if (qualifiesStudent) {
System.out.println("\nRecommended membership: Student Discount");
} else if (qualifiesBasic) {
System.out.println("\nRecommended membership: Basic Membership");
}
scanner.close();
}
}
PrimeClubMembership.main(null);
Enter your age:
Enter your annual income:
Are you a student? (yes/no):
What is your employment type? (full-time, part-time, unemployed):
Memberships you qualify for:
- Basic Membership
- Student Discount
Recommended membership: Student Discount