Creating a course eligibility checker in Android: parsing input and displaying results

I’m working on an Android app that helps students find out which college courses they’re eligible for based on their points. Here’s what I need to do:

  1. Show a list of available courses
  2. Each course has a point requirement (e.g., Biology: 28, Chemistry: 22)
  3. User enters their points
  4. App shows courses they can apply for

For example:

  • User input: 25 points
  • Output: “You can apply for: Chemistry, History” (as a ListView)

I’m using Android Studio and need help with the code. Here’s what I’ve tried so far:

public class CourseChecker extends Activity {
    String[] subjects = {"Biology", "Chemistry", "History", "Physics", "Literature"};
    int[] requirements = {28, 22, 20, 26, 18};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.course_checker);

        EditText pointsInput = findViewById(R.id.points_input);
        ListView eligibleCourses = findViewById(R.id.eligible_courses);

        // TODO: Implement points parsing and course filtering
        // TODO: Update ListView with eligible courses
    }
}

Any suggestions on how to complete this? Thanks!

Hey there SwimmingDolphin! :dolphin: Your course eligibility checker idea sounds pretty cool. Have you thought about adding any extra features to make it more user-friendly?

I’m curious - how are you planning to handle cases where a student’s points are exactly equal to a course requirement? Will they still be eligible or do they need to exceed it?

One thing you might want to consider is storing your course data in a more flexible format. Maybe use a HashMap or create a custom Course class? That way, it’d be easier to add or update courses in the future.

Also, have you considered adding a visual element to show how close a student is to qualifying for courses they’re not quite eligible for yet? Could be a nice motivational touch!

What’s been the trickiest part of the project so far? I’d love to hear more about your development process!

hey swimmin dolphin, cool project! i’d suggest using a hashmap for courses and points. something like:

Map<String, Integer> courses = new HashMap<>();
courses.put(“Biology”, 28);
courses.put(“Chemistry”, 22);
// add more courses

then u can easily filter eligible courses:

int userPoints = Integer.parseInt(pointsInput.getText().toString());
List eligible = courses.entrySet().stream()
.filter(e → userPoints >= e.getValue())
.map(Map.Entry::getKey)
.collect(Collectors.toList());

Here’s a way to implement the course eligibility checker:

First, create a Button in your layout to trigger the check. Then, in your onCreate method, add a click listener:

Button checkButton = findViewById(R.id.check_button);
checkButton.setOnClickListener(v -> checkEligibility());

Implement the checkEligibility method:

private void checkEligibility() {
    int points = Integer.parseInt(pointsInput.getText().toString());
    List<String> eligibleList = new ArrayList<>();

    for (int i = 0; i < subjects.length; i++) {
        if (points >= requirements[i]) {
            eligibleList.add(subjects[i]);
        }
    }

    ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
            android.R.layout.simple_list_item_1, eligibleList);
    eligibleCourses.setAdapter(adapter);
}

This should give you a working implementation. Remember to handle potential NumberFormatException when parsing the input.