Free Version
Difficult

# System Reliability Issues and Debugging

APCSA-LHYLWP

A programmer has developed the following method that is used to determine the percentage of times a golfer scores a par or better when they hit their drives in the fairway during a given round of golf. However, the computer system that calls this method frequently throws errors and returns inaccurate information, which has frustrated golfers who are trying to use the system to improve their scores.

Consider the following method.

// Parameters:
// fairways is the number of fairways they hit during the round
// parsOrBetter is the number of times the golfer scores par
// or better on the holes where they hit their drive in fairway
public static double calcPercentPars(int fairways, int parsOrBetter)
{
return parsOrBetter / fairways;
}


Which of the following would be the BEST way to change this method to improve its reliability?

A
public static double calcPercentPars(int fairways, int parsOrBetter)
{
double percent = parsOrBetter / fairways;
return percent;
}

B
public static double calcPercentPars(int fairways, int parsOrBetter)
{
if(fairways>0)
return (double) parsOrBetter / fairways;
return 0;
}

C
public static double calcPercentPars(int fairways, int parsOrBetter)
{
return (double) parsOrBetter / fairways;
}

D
public static double calcPercentPars(int fairways, int parsOrBetter)
{
double percent = (double) parsOrBetter / fairways;
if(fairways>0)
return percent;
return 0;
}

E
public static double calcPercentPars(int fairways, int parsOrBetter)
{
double percent = 0;
if(fairways>0)
percent = parsOrBetter / fairways;
else
percent = 0;
return percent;
}