There is a copy of the following code block in an interactive mode that you can modify and compile. Your task is to improve the codeโs style as an expert would view it, while ensuring its behavior remains unchanged. You may run your refactored code to verify that it still passes all test cases.
public class CampusHousing {
public static String getCampusHousingEligibility(int schoolYear, double GPA) {
if (schoolYear > 3 && GPA > 3.4) {
return "Eligible";
} else {
return "Not eligible";
}
}
}
You refactored correctly!
public class CampusHousing {
public static String getCampusHousingEligibility(int schoolYear, double GPA) {
if (schoolYear > 3 || GPA > 3.4) {
return "Eligible";
}
return "Not eligible";
}
}
The code doesnโt have the same functionality with the original one. Copy the original code into the interactive section and try refactoring it again.
public class CampusHousing {
public static String getCampusHousingEligibility(int schoolYear, double GPA) {
if (schoolYear <= 3 || GPA <= 3.4) {
return "Not eligible";
}
return "Eligible";
}
}
You refactored correctly!
public class CampusHousing {
public static String getCampusHousingEligibility(int schoolYear, double GPA) {
if (schoolYear <= 3 && GPA <= 3.4) {
return "Not eligible";
} else {
return "Eligible";
}
}
}
The code doesnโt have the same functionality with the original one. Copy the original code into the interactive section and try refactoring it again.