| about | help | code help+videos | done | prefs |
public boolean pizzaSliceParty(int slices, boolean isWeekend)
public boolean pizzaSliceParty(int slices, boolean isWeekend) {
boolean fun = false;
}
Step 2 The last line of the method will return that variable.
public boolean pizzaSliceParty(int slices, boolean isWeekend) {
boolean fun = false;
return fun;
}
Step 3 Add an if () statement block. The body of the block will assign the return variable a different value (in this case true)
public boolean pizzaSliceParty(int slices, boolean isWeekend) {
boolean fun = false;
if () {
fun = true;
}
return fun;
}
Step 4 Use one of the parameters in the condition of the if() statement (between the parentheses).
public boolean pizzaSliceParty(int slices, boolean isWeekend) {
boolean fun = false;
if ( isWeekend ) {
fun = true;
}
return fun;
}
Step 5 Add a second NESTED if() statement to the body of the if() statement, i.e. INSIDE if (isWeekend) { Move the return value assignment statement to the body of this new NESTED if() statement
public boolean pizzaSliceParty(int slices, boolean isWeekend) {
boolean fun = false;
if ( isWeekend ) {
if () {
fun = true;
}
}
return fun;
}
Step 6 Use the second parameter appropriately in the condition of the NESTED if() statement.
public boolean pizzaSliceParty(int slices, boolean isWeekend) {
boolean fun = false;
if ( isWeekend ) {
if ( 40 <= slices ) {
fun = true;
}
}
return fun;
}
Step 7 DUPLICATE the entire structure of the NESTED if statements. Change the condition of the OUTER if() statement to its OPPOSITE
public boolean pizzaSliceParty(int slices, boolean isWeekend) {
boolean fun = false;
if ( isWeekend ) {
if ( slices >= 40 ) {
fun = true;
}
}
if ( !isWeekend ) { // NOT isWeekend
if ( 40 <= slices ) {
fun = true;
}
}
return fun;
}
Step 8 Modify the condition of the INNER (nested) if() statement to be consistent with what the problem requires.
public boolean pizzaSliceParty(int slices, boolean isWeekend) {
boolean fun = false;
if ( isWeekend ) {
if ( 40 <= slices ) {
fun = true;
}
}
if ( !isWeekend ) { // NOT isWeekend
if ( 40 <= slices && slices <= 60 ) {
fun = true;
}
}
return fun;
}
pizzaSliceParty(30, false) → false pizzaSliceParty(50, false) → true pizzaSliceParty(70, true) → true ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 2
Copyright Nick Parlante 2017 - privacy