Question: Need help to condense this code block. public java.lang.String getResult() { this.getArraySum(); if (this.sumOfArray > this.guessTargNumber) { if (this.guess == 'Y') { return You guessed

Need help to condense this code block.

public java.lang.String getResult() { this.getArraySum(); if (this.sumOfArray > this.guessTargNumber) { if (this.guess == 'Y') { return "You guessed correctly! The sum was " + this.sumOfArray + "!"; } else { return "You guessed wrong! The sum was " + this.sumOfArray + "!"; } } else { if (this.guess == 'Y') { return "You guessed wrong! The sum was " + this.sumOfArray + "!"; } else { return "You guessed correctly! The sum was " + this.sumOfArray + "!"; } } }

It needs to be 2 or less returns. Maybe a local variable can be added and used?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!