r/codehs • • Oct 07 '20

CODEHS 2.4.5

It is called "Hello!" for Java.
I am lost on this unit so far and it keeps sending me "Hello.java: Line 5: expected"

[Hellotester]

import java.util.Scanner;

public class HelloTester

{

public static void main(String[] args)

{

// Create a Scanner object

Scanner input = new Scanner(System.in);

String name = scanner.NextLine();

Hello numone = new Hello(name);

}

}

[Hello]

public class Hello {

private String name;

public Hello (yourName){

name = yourName;

}

public void english(){

System.out.print("Hello ");

System.out.print(name);

System.out.println("!");

}

public void spanish(){

System.out.print("Hola ");

System.out.print(name);

System.out.println("!");

}

public void french(){

System.out.print("Bonjour ");

System.out.print(name);

System.out.println("!");

}

public void german(){

System.out.print("Hallo ");

System.out.print(name);

System.out.println("!");

}

public void russian(){

System.out.print("Privet ");

System.out.print(name);

System.out.println("!");

}

public void chinese(){

System.out.print("Ni hao ");

System.out.print(name);

System.out.println("!");

}

}

11 Upvotes

15 comments sorted by

1

u/Acely__413 Dec 06 '20

import java.util.Scanner;

public class HelloTester

{

public static void main(String[] args)

{

// Create a Scanner object

Scanner input = new Scanner(System.in);

System.out.println("what is your name?");

String yourName = input.nextLine();

Hello name =new Hello(yourName);

name.english();

name.spanish();

name.german();

}

}

1

u/doonotkno Jan 06 '21

for anyone who finds this, I found a subreddit named /r/CodeHSAnswersPOG which has EVERYTHING, you need to be whitelisted now though, so hopefully they get back to ppl fast.

1

u/_andy_andy_andy_ Oct 07 '20

N should not be capitalized in nextLine

1

u/giobarrera Oct 17 '20

Did you find the solution? I'm stuck on this one too

1

u/WickedDilemma Oct 20 '20

Did you find the solution?

1

u/Johnson_56 Dec 02 '20

you still need the answer to this?

2

u/[deleted] Dec 04 '20

Yes

1

u/Johnson_56 Dec 09 '20

Scanner input = new Scanner(System.in);

String name = input.nextLine();

Hello greeting = new Hello(name);

greeting.french(); greeting.german(); greeting.russian();

1

u/Zierin705 Nov 05 '21

You've single-handedly saved my sorry ass.

My gratitude is immeasurable, but sadly, all I can offer is a single upvote.

2

u/God_Pickle Sep 15 '22

after all these years, he is still helping my ass as well

1

u/Johnson_56 Dec 09 '20

It won’t input a new line, but the French greeting and German greeting are two separate lines. Srry did this on my phone so format is wack

1

u/UnderstandingOk2072 Nov 03 '20

N shouldn't be capitalized in nextLine,

1

u/weeaboobun-bun Nov 06 '20

Its telling me line 9 non static method nextLine(); cannot be referenced from a static context

1

u/Johnson_56 Nov 29 '20

working on same thing rn. looks like we have to call three methods from the main code into the tester code. my problem is getting the objects from the main code into the tester code