Public class Game
Public int getScore(){
int result=0;
if(levelOne.goalReached())
{
result += levelOne.getPoints();
if(levelTwo.goalReached())
{
result += levelTwo.getPoints();
if(levelThree.goalReached())
{
result += levelThree.getPoints();
}
}
}
if(isBonus())
result *= 3;
return result;
}
Frq question 1b
public int playManyTimes(int num) {
int max= Integer.MIN_VALUE
for(int i=0; i<num; i++){
play();
int current = getScore();
if(current>max){
max=current;
}
}
return max;
}
FRQ Question 2 Code:
public class Textbook extends Book
{
private int edition;
public Textbook(String bookTitle, double bookPrice, int edition)
{
super(bookTitle, bookPrice);
this.edition = edition;
}
public int getEdition()
{
return edition;
}
public String getBookInfo()
{
return super.getBookInfo() + "-" + edition;
}
public boolean canSubstituteFor(Textbook otherTextbook)
{
if(this.getTitle().equals(otherTextbook.getTitle()) &&
this.getEdition() >= otherTextbook.getEdition();){
return false;
}
else{
return true;
}
}
}