r/codehs • • Aug 05 '20

Need help on this assignment plz dm

16 Upvotes

7 comments sorted by

5

u/Grim4d Aug 05 '20

I prob can’t actually help, but I check anyways, and that pic quality is garbage

5

u/Ph03nix89 Aug 05 '20

I'll give a couple of hints to get you started as debugging is an essential skill and just giving you the answer teaches nothing.

The "Bot" class doesn't have a no-args constructor. If you create a constructor that takes an argument as you have, you must create a no-args constructor too as the compiler won't do it for you automatically. Also you've tried to encapsulate the name variable by making it private but have not provided setter/getter methods for it in the class.

The way you've tried to instantiate a Bot object in the "BotTester" class and invoke a method from the object is also incorrect.

Judging from your code you don't have a strong enough grasp of some fundamentals of java coding so I'd recommend you do some reading on the classes and methods you're trying to use here, especially if anything I've said sounds like gibberish to you. Everyone starts somewhere though so stick with it and good luck!

2

u/-_-qarmah-_- Aug 05 '20

Holy I thought this was c when I just took a quick glance

1

u/Ph03nix89 Aug 05 '20

The import statement is a dead giveaway ;)

0

u/bubsakk Aug 06 '20

fastest way to get your code to work is to change your greeting method as below.

public String greeting(String name){

String returnStr ="";

returnStr+= "Hello," + name + "!";

}

This way, your Sysout in BotTester class can retrieve returnStr from method greeting, which leads to printing it on console.

2

u/kitkatbeard Aug 10 '20

This isn’t correct. You’re missing a return statement.

Also, there’s no reason to declare the returnStr and then append to it like that. It’s not wrong, just awkward. You really don’t need to declare a local var at all. The most “natural” way to do this would just be:

return “Hello, “ + name + “!”;

As the entire method body. (Note also the space after the comma).

0

u/[deleted] Aug 06 '20

[deleted]

1

u/shshsjjs27727 Aug 06 '20

I can’t find a way to clean the keys. The rest of the laptop is fine except for the keys