Photo AI

A group of mountain passes has been selected to determine specific statistics, such as the number of travellers, fines received by travellers and details about the danger levels of the mountain passes - NSC Information Technology - Question 2 - 2016 - Paper 1

Question icon

Question 2

A-group-of-mountain-passes-has-been-selected-to-determine-specific-statistics,-such-as-the-number-of-travellers,-fines-received-by-travellers-and-details-about-the-danger-levels-of-the-mountain-passes-NSC Information Technology-Question 2-2016-Paper 1.png

A group of mountain passes has been selected to determine specific statistics, such as the number of travellers, fines received by travellers and details about the d... show full transcript

Worked Solution & Example Answer:A group of mountain passes has been selected to determine specific statistics, such as the number of travellers, fines received by travellers and details about the danger levels of the mountain passes - NSC Information Technology - Question 2 - 2016 - Paper 1

Step 1

1.1 An object class called TMountainPass/MountainPass

96%

114 rated

Answer

Define a class named TMountainPass, including four parameters:

  • distance (Double)
  • speedLimit (Integer)
  • dangerLevel (String)
  • averageRainfall (Double)

Initialize these attributes in the constructor:

public TMountainPass(double distance, int speedLimit, String dangerLevel, double averageRainfall) {
    this.distance = distance;
    this.speedLimit = speedLimit;
    this.dangerLevel = dangerLevel;
    this.averageRainfall = averageRainfall;
}

Step 2

1.2 A mutator method named setDangerLevel

99%

104 rated

Answer

Implement the setDangerLevel method to update the danger level:

public void setDangerLevel(String dangerLevel) {
    this.dangerLevel = dangerLevel;
}

Step 3

1.3 A method named calculateFine

96%

101 rated

Answer

Create the calculateFine method:

public double calculateFine(int timeTravelled, double speed) {
    double fine = 0;
    double avgSpeed = speed / (timeTravelled / 60.0);

    if (avgSpeed > speedLimit) {
        fine = 500 + (avgSpeed - speedLimit) * 100;
    }
    return fine;
}

Step 4

1.4 A method named suggestedDangerLevel

98%

120 rated

Answer

Define the suggestedDangerLevel method:

public String suggestedDangerLevel(double avgRainfall) {
    if (avgRainfall >= 10) {
        return "High";
    } else if (avgRainfall >= 5) {
        return "Medium";
    } else {
        return "Low";
    }
}

Step 5

2.1 Button [Question 2.2.1]

97%

117 rated

Answer

For this button, determine the selected mountain pass:

String selectedPass = radioButtonsGroup.getSelected();
// assuming the radioButtonsGroup contains the passes

Step 6

2.2 Button [Question 2.2.2]

97%

121 rated

Answer

Display information based on user input:

mountainPassObject.getMountainPassInfo();

Step 7

2.3 Button [Question 2.2.3]

96%

114 rated

Answer

Calculate fine based on speed and time:

double fine = calculateFine(timeTravelled, speed);
// Display fine formatted as currency

Step 8

2.4 Button [Question 2.2.4]

99%

104 rated

Answer

Display rainfall data, check and update danger level:

double rainfall = arrRain[selectedPassIndex][currentDay];
String dangerLevel = suggestedDangerLevel(rainfall);

Join the NSC students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

;