#Java output requiring me to hit enter twice for the first question.

1 messages · Page 1 of 1 (latest)

stuck duneBOT
#

<@&987246399047479336> please have a look, thanks.

#

I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.

bold nexus
#

there is a lot wrong with this:

 else if (first.equals ("B")); {

so first remove the ; after the if, it is going to close the if and everything that comes after isnt in the else if statement even if it kinda looks like it

#

also there is a missing closing bracket before that if else

#

proper formatting would make this issue more clear

#
String first = scanletter.nextLine();
if (first.equals ("A")) {
  System.out.println ("You get up, and get ready for the day.");
  System.out.println ("Your Father tells you that \"we have two choices, either go to church or watch mass online");
  System.out.println ("A: watch a 20 minute mass on YouTube.");
  System.out.println ("B: Go to church.");
}

String a = scanletter.nextLine();
if (a.equals ("A")) {
    System.out.println ("After a 20 second ad on sandels, you watch church on Youtube");
} else if (first.equals ("B")); 

{
    System.out.println ("Your Father bangs on the door saying \"we need to go to CHURCH\"");
    System.out.println ("What will your response be?");
    System.out.println ("A: Go to hell");
    System.out.println ("B: Sorry for oversleeping");

    String second = scanletter.nextLine();
    if (second.equals ("A")) {
        System.out.println ("He tells you \"Your phone will be taken if you don't get ready right now!.\"");
        System.out.println ("What will your response be?");
        System.out.println ("A: Good, it's hard to be on a phone when your being a prick.");
        System.out.println ("B: Fine whatever, I'll get ready.");

        String BA = scanletter.nextLine();
        if (second.equals ("A")) {
            System.out.println ("He comes over, and takes away your phone, keys, and laptop.");
            System.out.println ("Since he took away your laptop, you & this code does not exist anymore!");
            System.out.println ("You loose!");
        }
    }
}
#

this is your code

#

also you shouldnt add these completely useless comments

#

only add meaningfull comments to your code

bold nexus
obsidian yew
#

thankyou so much! sorry it's my first year in computer science 1

#

I removed the ; and the B is still wanting to be entered twice.

#

Is this because it's not in the if else statment?

#

Is this so it hides it by adding new lines to everyone before?

trail haven
obsidian yew
clever rover
#

Your second scanner a is in the same scope as the first scanner.
Because of that , if it's not "A", it will scan again.

bold nexus
obsidian yew
stuck duneBOT
obsidian yew
clever rover
# obsidian yew here is my new file:

I don't know if you're identing like that on purpose or if it's just a mistake on copy/pasting your code, but here we have the same scope problem. We can say a scope can be created with open and close braces {}, just identing won't solve the problem of the Fl scanner scanning right after the first when you type "B".
In other words, the Fl scanner is still being read before the "B" check. (the line right below your //B Scanner comment line)

#

in java, identing will not change the program execution order, it's just readability for us humans

obsidian yew
#

I am going to redo this assignment tomorrow and follow more proper formatting!

clever rover
#

yw ^^
After bringing up the lines, remember to cover the case "A" -> "B" after going to church, since the program just ends after that.
And also deleting the comma ; on

 else if (first.equals ("B")); {

as Squid mentioned.