Question

In: Computer Science

boolean isEligibile (int, char, char) using Drjava isEligibile will return true when the customer is eligible...

boolean isEligibile (int, char, char) using Drjava
isEligibile will return true when the customer is eligible to book a vacation package, and false otherwise. It takes as input 3 pieces of information, first an int representing the customer’s age. Second, a char representing the country where the rental is being made (‘c’ for Canada, ‘u’ for United States, ‘f’ for France). The third input is a char representing if the customer has a valid Canadian passport ‘y’ for Yes, ‘n’ for No.
A customer is eligible to book a package under the following conditions:
If the customer is in Canada, they must be over 21.
If the customer is in the United States, they must be over 18.
If the customer is in France, they must be over 25.
If the customer does not have a valid passport, they are not eligible to book a package in France or the United States.

Solutions

Expert Solution

The code for the function "isEligible()" is as follows:

public static boolean isEligible(int age, char country, char passport) {

                if( ('n' == passport && 'f' == country) || ('n' == passport && 'u' == country) ) {
                        return false;
                }
                else if( (country == 'c' && age > 21) || (country == 'u' && age > 18) || (country == 'f'  && age > 25) ) {
                        return true;
                } else {
                        return false;
                }
        }

In order to test the functionality of the above function, we need to have the Tester Class. So the code for the Tester class which contain the main class is:

class EligibleTest {
        public static boolean isEligible(int age, char country, char passport) {

                if( ('n' == passport && 'f' == country) || ('n' == passport && 'u' == country) ) {
                        return false;
                }
                else if( (country == 'c' && age > 21) || (country == 'u' && age > 18) || (country == 'f'  && age > 25) ) {
                        return true;
                } else {
                        return false;
                }
        }
        public static void main(String args[]) {
                // Testing Code 
                // when the customers have the passport with him/her

                //If the customer is in Canada, they must be over 21.
                System.out.println(isEligible(22, 'c', 'y'));

                //If the customer is in the United States, they must be over 18.
                System.out.println(isEligible(19, 'u', 'y'));
                
                //If the customer is in France, they must be over 25.
                System.out.println(isEligible(26, 'f', 'y'));


                // when the customers does not have the passport with him/her

                //If the customer does not have a valid passport, they are not eligible to book a package in France
                System.out.println(isEligible(22, 'u', 'n'));

                //If the customer does not have a valid passport, they are not eligible to book a package in  the United States.
                System.out.println(isEligible(27, 'f', 'n'));

                // If the customer does not have a valid passport, but he is applicable age wise than the function can return true
                System.out.println(isEligible(22, 'c', 'n'));
        }
}

The output is:

If you have any doubts let me know in the comments section. Thank you


Related Solutions

double calculateCost (char, int, int) with Drjava calculateCost will compute and return the cost of the...
double calculateCost (char, int, int) with Drjava calculateCost will compute and return the cost of the vacation It will take as input 3 pieces of information. First, a char representing the type of room being rented (‘d’ double, ‘k’ kingsize, ‘p’ for penthouse). The second input is an int representing the number of days they will stay, the last input is an int representing the number of people staying. To compute the cost of the stay we start with a...
public boolean isPrime(int num){ // return true if the number is prime, false otherwise } public...
public boolean isPrime(int num){ // return true if the number is prime, false otherwise } public boolean isOdd(int num){ // return true if the number is odd, false otherwise } public String reverseMyString(String input){ // using a loop, reverse a string // i.e. input = "hello", reversed answer: "olleh" // i.e. input = "bye", reversed answer: "eyb" } public int pow(int base, int power){ // using for loop, calculate base raised to power // i.e. base = 2, power =...
Write function boolean isSorted(int a[], int size). The function returns true if array a is sorted...
Write function boolean isSorted(int a[], int size). The function returns true if array a is sorted in either ascend order or descend order; false otherwise. c++
I don't understand why this method will not return true, even when my parameters for boolean...
I don't understand why this method will not return true, even when my parameters for boolean results are met, can anyone help shed some light on my mistake? import java.util.*; public class PasswordChecker{    public static void main (String[]args){ Scanner scan = new Scanner(System.in); System.out.println("Please enter a password that is 8 characters in length."); System.out.println("The password must have at least 3 uppercase letters,"); System.out.println("3 numeric digits, as well as 2 lowercase letters,"); System.out.println("and contain no special characters."); System.out.println(); System.out.println("Enter a...
c program //the file's size in bytes unsigned int fileSize(const char* name){     return 0; }...
c program //the file's size in bytes unsigned int fileSize(const char* name){     return 0; } //same as fileSize except if the file is a directory then it recursively finds the size of directory and all files it contains unsigned int fileSizeRec(const char* name){     return 0; }
complete the program #include <cstdlib> #include <iostream> #include <iomanip> using namespace std; int main(int argc, char**...
complete the program #include <cstdlib> #include <iostream> #include <iomanip> using namespace std; int main(int argc, char** argv) { int number, sum, count; // Write a while loop that reads a number from the user and loop // until the number is divisible by 7 cout << "What is the number? "; cin >> number; while ( ... ) { ... } cout << number << " is divisible by 7!! << endl << endl; // Write a for loop that...
Consider the following two methods: public static boolean isTrue(int n){ if (n <= 1)          return false;...
Consider the following two methods: public static boolean isTrue(int n){ if (n <= 1)          return false;        for (int i = 2; i < n; i++){          if (n % i == 0)             return false; }        return true; } public static int Method(int[] numbers, int startIndex) { if(startIndex >= numbers.length) return 0; if (isTrue(numbers[startIndex]))      return 1 + Method(numbers, startIndex + 1); else      return Method(numbers, startIndex + 1); } What is the final return value of Method() if it is called with the...
write the algorithm for this the code?!. #include<iostream> using namespace std; #include<string.h> int main() { char...
write the algorithm for this the code?!. #include<iostream> using namespace std; #include<string.h> int main() { char plain[50], cipher[50]="", decrypt[50]=""; int subkeys[50], len;       cout<<"Enter the plain text:"<<endl; cin>>plain;    cout<<"Enter the first subkey:"<<endl; cin>>subkeys[0];    _strupr(plain);    len = strlen(plain);    /**********Find the subkeys**************/    for(int i=1; i<len; i++) { if ((plain[i-1]>='A') && (plain[i-1]<='Z')) { subkeys[i] = plain[i-1]-65; } }    /****************ENCRYPTION***************/       for(int i=0; i<len; i++) { if ((plain[i]>='A') && (plain[i]<='Z')) {    cipher[i] = (((plain[i]-65)+subkeys[i])%26)+65; }...
***Convert the C++ to Python*** #include <iostream> using std::cout; using std::cin; using std::endl; int charClass; char...
***Convert the C++ to Python*** #include <iostream> using std::cout; using std::cin; using std::endl; int charClass; char lexeme[100]; char str[200]; char nextChar; const int LETTER = 0; const int DIGIT   = 1; const int UNKNOWN = -1; const int OPAREN = 2; const int CPAREN = 3; const int PLUS = 4; const int MINUS = 5; const int MUL = 6; const int DIV = 7; const int ID_CODE = 100; const int PLUS_CODE = 101; const int MINUS_CODE =...
I want Algorithim of this c++ code #include<iostream> using namespace std; int main() { char repeat...
I want Algorithim of this c++ code #include<iostream> using namespace std; int main() { char repeat = 'y'; for (;repeat == 'y';){ char emplyeename[35]; float basic_Salary,EPF, Dearness_Allow, tax, Net_Salary , emplyee_id; cout << "Enter Basic Salary : "; cin >> basic_Salary; Dearness_Allow = 0.40 * basic_Salary; switch (01) {case 1: if (basic_Salary <= 2,20,00) EPF = 0; case 2: if (basic_Salary > 28000 && basic_Salary <= 60000) EPF = 0.08*basic_Salary; case 3: if (basic_Salary > 60000 && basic_Salary <= 200000)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT