CSA FRQ
CSA FRQ
import java.util.Scanner;
import java.util.Arrays;
public class Level {
int level;
String levelStatus;
public boolean goalReached() {
if (levelStatus.equals("y")) {
return true;
} else {
return false;
}
}
public int getPoints() {
if (level == 1 && goalReached() == true) {
return 200;
} else if (level == 2 && goalReached() == true) {
return 100;
} else if (level == 3 && goalReached() == true) {
return 500;
}
return 0;
}
}
public class Game {
private Level levelOne = new Level();
private Level levelTwo = new Level();
private Level levelThree = new Level();
//Default constructor created
// public Game() { }
String bonusStatus;
public void play() {
System.out.println("Game Simulation");
Scanner numInput = new Scanner(System.in);
System.out.println("How many times are you playing the game?");
int num = numInput.nextInt();
playManyTimes(num);
}
public boolean isBonus() {
if (bonusStatus.equals("y")) {
return true;
} else {
return false;
}
}
public int getScore() {
int score = 0;
if (levelOne.goalReached() == true) {
score += levelOne.getPoints();
if (levelTwo.goalReached() == true) {
score += levelTwo.getPoints();
if (levelThree.goalReached() == true) {
score += levelThree.getPoints();
}
}
}
if (isBonus() == true) {
score *= 3;
}
return score;
}
public int playManyTimes(int num){
Scanner userInput = new Scanner(System.in);
int[] scoreArray = new int[]{};
scoreArray = Arrays.copyOf(scoreArray, scoreArray.length + num);
for (int w = 0; w < num; w++) {
scoreArray[w] = 0;
}
for (int i = 0; i < num; i++) {
System.out.println("Did you complete level 1? (y/n)");
levelOne.levelStatus = userInput.nextLine();
levelOne.level = 1;
levelOne.goalReached();
System.out.println("Did you complete level 2? (y/n)");
levelTwo.levelStatus = userInput.nextLine();
levelTwo.level = 2;
levelTwo.goalReached();
System.out.println("Did you complete level 3? (y/n)");
levelThree.levelStatus = userInput.nextLine();
levelThree.level = 3;
levelThree.goalReached();
System.out.println("Is this a bonus game? (y/n)");
bonusStatus = userInput.nextLine();
int individualScore = getScore();
System.out.println(individualScore);
scoreArray[i] = individualScore;
}
int highScore = 0;
for (int a = 0; a < scoreArray.length; a++) {
if (a == 0) {
highScore = scoreArray[a];
} else if (a > 0 && scoreArray[a] > scoreArray[a - 1]) {
highScore = scoreArray[a];
} else if (a > 0 && scoreArray[a] < scoreArray[a - 1]) {
highScore = scoreArray[a - 1];
}
}
System.out.println("Your high score was: " + highScore);
return highScore;
}
}
public class testGame {
public static void main(String[] args) {
Game g = new Game();
g.play();
}
}
testGame.main(null);