r/programminghelp • • Sep 25 '18

Can I have help with the classes and methods on my Java homework?

I am using BlueJ 3.1.5.

My program is supposed to run from two classes and return a string that is a randomly generated password of a length input by the user. By comparing my current code with other programs I have run before it should work and compiles fine, but instead does not give any error messages or even open a console window. This is my first time running a program through more than one class at a time and I feel that that is where the problem most likely lies. I am not sure how I should add my code to this post but if anyone is able to help I can figure out some way to send it to you.

3 Upvotes

14 comments sorted by

1

u/FredTargaryen Sep 25 '18

It's been a while since I used BlueJ but if you're running the class that contains public static void main(String [] args), and both classes compiled without errors, it should run ok...

1

u/[deleted] Sep 25 '18

No console is opened at all, even though i have multiple lines that should print something to the console (System.out.println(~~~~))

1

u/FredTargaryen Sep 25 '18

Are you able to run the program from cmd/shell?

1

u/[deleted] Sep 25 '18

I am on mac so i have no cmd/shell i don’t think

2

u/FredTargaryen Sep 25 '18 edited Sep 25 '18

Your terminal I mean. Go>Utilities>Terminal it looks like

1

u/[deleted] Sep 25 '18

Are you pausing the console?

1

u/[deleted] Sep 25 '18

No, i can still run other programs fine

1

u/FredTargaryen Sep 25 '18

According to a StackOverflow thing I just saw it's possible that the statement that reads input won't necessarily open the console, and you can make the console open with a print statement before the input statement. Does your code do that?

Seeing your code via pastebin or something might be useful for us.

2

u/[deleted] Sep 25 '18

password generator: pastebin.com/tA24hXkB

runner class: pastebin.com/vm3KBXed

2

u/FredTargaryen Sep 25 '18

Well I don't see anything wrong with your code, but my best theory right now is the console not opening because it hasn't been made to open with a print statement. Please could you try inserting a print statement at the start of main?

3

u/[deleted] Sep 25 '18

That did it! Thank you!

2

u/FredTargaryen Sep 25 '18

No worries! At this point I'd like to recommend a couple of different IDEs. BlueJ is fine for less complex programs but one day you will start noticing features that would be useful, but it doesn't have. Eclipse is extremely popular but I prefer IntelliJ IDEA.

Maybe the most authentic way of running your programs is via a command, i.e "java main" in your Terminal to run main.class. That way it's already in a console and you don't need a print statement to open one.

2

u/[deleted] Sep 25 '18

unfortunately bluej is the program my teacher has our whole class using, but i will check out those others and see if i can use them instead

1

u/FredTargaryen Sep 25 '18

In that case your teacher will probably talk to the class about other IDEs eventually anyway