Skip to content

Instantly share code, notes, and snippets.

@victoryforphil
Created December 13, 2018 17:08
Show Gist options
  • Save victoryforphil/73302882d0a642f1220c7ca62e361d04 to your computer and use it in GitHub Desktop.
Save victoryforphil/73302882d0a642f1220c7ca62e361d04 to your computer and use it in GitHub Desktop.
Questions for FRQ in APCSA, turned in 12/13/2018. Alex Carter
/*
Alex Carter @ GTHS
12/13/2018
[email protected]
*/
// Question 1
public int[] replaceHighAndLow(int[] arr){
for(int i=0;i<arr.length;i++){
if(arr[i] > 750){
arr[i] = 1000;
}else{
arr[i] = 0;
}
}
}
//Question 2
public boolean isIncreasing(ArrayList<Integer> arr){
int last = Integer.MIN_VAL; // Set this to lowest value possible
for(int val : arr){
if(val < last){
return false; // if it gets smaller, return early false
}
last = val; // Set last value
}
return true; // else return true
}
// Question 3
public int findCount(String[][] arr, String target){
int count = 0;
for(String song : arr){ // Loop through first array of songs
for(String word : song){
if(word == target){
count++;
}
}
}
return count;
}
//Question 4
public int[] overpriced(double[] rsiValues){
int[] results = new int[rsiValues];
for(int i=0;i<rsiValues.length;i++){
if(rsiValues[i] > 70){
results[i] = 1;
}else{
results[i] = 0;
}
}
return results;
}
// Question 5
public static int[] onlyEvens(int arraySize, int range){
int[] result = new int[arraySize];
for(int i=0;i<arraySize;i++){
boolean foundNum = false; // Did i find a even number
int number = -1;
while(!foundNum){ // Make new numbers untul we make a even one.
number = Random.nextInt(range);
foundNum = number % 2 == 0; // Returns true if the number is even
}
result[i] = number;
}
return result;
}
// Question 6
public boolean rateIsIncreasing(ArrayList<Double> stockPrices){
for(int i=0;i<stockPrices.length;i++){
double val = stockPrices[i];
if(i != 0){ // Not first element
double last = stockPrices[i-1]; // Get previous element
if(val < last){
return false; // if the rate decreases, return false early.
}
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment