I have a method that returns true or false,
public boolean confirmVotes()
{
System.out.println("Your vote for President is:" + getVotes() );
System.out.println("your vote for Vice President is:" + getVotes());
System.out.println("Is this correct? Yes or No?");
Scanner keyboard = new Scanner(System.in);
String answer = keyboard.nextLine();
if (answer.equalsIgnoreCase("Yes"))
return true;
else
return false;
}
How do i use this return statement in another method? This is what i am trying to do
public void recordVote()
{
if comfirmVotes returns true for X
do this for y
}
If you inspect your confirmVotes method, you will notice that you’ve already solved this problem:-
.equalsIgnoreCase(String s) is a method which returns a boolean, and you’ve already constructed an if statement based on its return value. Thus:-
Also worthy of note, you can replace:-
with:-