Advertisement
APCS_IS_HARD

ElevationInfo

Apr 9th, 2020
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class ElevationInfo {
  4.     // The array of elevations
  5.     private int[] elevations;
  6.  
  7.     // Constructor not shown
  8.     public boolean allUphill() {
  9.         for (int i = 0; i < elevations.length; i++) {
  10.             if (i != 0){
  11.                 if( elevations[i - 1] > elevations[i]) {
  12.                     return false;
  13.                 }
  14.             }
  15.         }
  16.         return true;
  17.     }
  18.  
  19.     public int amountOfClimb() {
  20.         int sum = 0;
  21.         for (int i : elevations) {
  22.             sum+=i;
  23.         }
  24.         return sum;
  25.     }
  26.  
  27.     public int highestPeakIndex() {
  28.         int max = 0;
  29.         for (int i : elevations) {
  30.             if (i > max){max = i;}
  31.         }
  32.         return max;
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement