#Should I just email my TA?

54 messages · Page 1 of 1 (latest)

supple herald
#

So I submitted an assignment with code in it obviously and got an error like this...

What could've gone wrong?

carmine kettle
#

@supple herald it’s because you’re using nextInt and that doesn’t clear the new line character you added when pressing enter. So the next time you try to get user input, it just fills that with the leftover new line

#

Read about it here

supple herald
#

but when i add input.nextLine(); under the nextInt() line i get an actual error

proven finch
#

I don't think that was the real problem, but you're still supposed to tell what is the "actual error". Normally you wouldn't have an error when doing that

supple herald
#

when i added it it was asking me to initialize input as a variable which doesn't make sense

proven finch
#

When I said "tell" I meant "show", and you really shouldn't need to be told something so obvious

supple herald
proven finch
#

.... scan

#

scan.nextLine();

supple herald
#

omfg

#

im sorry

#

im so sorry

proven finch
#

No that part is non apologizing worthy. We've all been there

supple herald
#

lemme see if autograder reads it now

#

nope.

#

still didnt read my code

proven finch
#

Yeah. If you ask me the error report is unhelpful

supple herald
proven finch
#

Though it looks like, from the expectations, you're supposed to be able to handle incorrect user input

supple herald
#

it just tells me it failed to compile

proven finch
#

Failed to compile? Dang

supple herald
#

well with incorrect user input i made it so that the program ends

#

because thats what my lab asked me to do

proven finch
#

It's a problem when it compiles fine on your computer and not on the grading lab

supple herald
#

yeah, i think im just going to email my Ta

proven finch
#

We could try and guess when seeing your entire file, but honestly...

supple herald
#

public class Lab11A {
    public static void menu(){
        System.out.println("Menu");
        System.out.println("0) Hello World");
        System.out.println("1) Goodbye Moon");
        System.out.println("2) Walking on Sunshine");
        System.out.println();

        System.out.print("What would you like to do: ");
    }

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int choice;
        String response;

        do{
            menu();
            choice = scan.nextInt();
            scan.nextLine();

            switch(choice){
                case 0 -> {
                    System.out.println();
                    System.out.println("Hello!");
                    System.out.println();
                }
                case 1 -> {
                    System.out.println();
                    System.out.println("Ok, bye.");
                    System.out.println();
                }
                case 2 -> {
                    System.out.println();
                    System.out.println("WHOA!");
                    System.out.println();
                    }
                }

            System.out.print("Type YES to rerun. ");
            response = scan.nextLine();
            System.out.println();

            }while(response.equalsIgnoreCase("yes"));

            System.out.println("Program Ends");
    }
}```
#

i mean

#

idk i feel like i did everything right

proven finch
#

It's not impossible that the lab would not like -> styled switch

#

Have you seen it work before?

supple herald
#

?

#

wdym styled switch

proven finch
#

switch that uses the -> syntax

#

older switch syntax uses case STUFF: and a break later

supple herald
#

idk how the autograder works this is my first time using it

proven finch
#

Doesn't cost much to try the older syntax first

supple herald
#

but my lab11B program is quite similar and the autograder was able to run it

proven finch
#

similar okay, but does it do a switch like that?

supple herald
#

well originally u just used a while loop

#

i got the same error

#

so i switch it to a do while

#

and it still gives me the error

#

and yes

#

it does do a switch

#

like that

proven finch
#

It would be interesting to compare the program that works and the one that doesn't, but yeah, I guess help from the TA will be needed

supple herald
#

omg

#

i fixed it

#

i added a break; even thought it was redundant and it worked

#

i love gradescope!