You are on page 1of 3

6/8/22, 1:31 PM Solve my Homework - Homeworkify.

Net


U a

Answer
Algorithm, output screenshot and source code (in Java) for the above question:

ALGORITHM:

1. Input name and age of the applicant

2. if slot==0 PRINT "Basketball team is no longer accepting applicants" and program


terminates.

3. if 18>= age <=21, PRINT "Welcome to the Basketball Team!".

4. if age <=18 or age >=21, PRINT "Sorry, you are not qualified!".

OUTPUT SCREENSHOT:

SOURCE CODE:

import java.util.*;

public class Main

https://homeworkify.net/solve-my-homework/ 1/3
6/8/22, 1:31 PM Solve my Homework - Homeworkify.Net

    //variable to keep track of number of available slots

    static int slot=2;

    

    //isQualified method to check applicant's eligibility

    static boolean isQualified(int age)

    {

        //if age is between 18 to 21 return true

        if(age>=18&&age<=21)

        {

            --slot;

            return true;

        }

        

        //if not then return false

        return false;

    }

    

    //main method

    public static void main(String[] args) {

        

        //Scanner object to take input

        Scanner sc = new Scanner(System.in);

        

        //while loop until there are slots left

        while(true)

        {

        

        System.out.println("Basketball Team Application");


        System.out.println("-- -- -- -- -- -- -- -- -- -- -- -- -");

        

        if(slot<2)

        sc.nextLine();

        

        //input name of the applicant

        System.out.print("Enter name of applicant: ");

        String name=sc.nextLine();

        

        //input age of the applicant

        System.out.print("Enter age of applicant: ");

        int age=sc.nextInt();

        

https://homeworkify.net/solve-my-homework/ 2/3
6/8/22, 1:31 PM Solve my Homework - Homeworkify.Net

        //if there are no slots left then print message break out from the loop

        if(slot==0)

        {

        System.out.println("Basketball team is no longer accepting applicants.");

        break;

        }

        

        //calling isQualified method

        boolean check = isQualified(age);

        

        if(check==true)

        System.out.println("Welcome to the Basketball Team!");

        

        else

        System.out.println("Sorry, you are not qualified!");

        

        System.out.println();

        }

        

    }

}
Reviews: Likes: 0 Dislikes: 0

©Homeworkify.Net 2022.

https://homeworkify.net/solve-my-homework/ 3/3

You might also like