• Post Reply Bookmark Topic Watch Topic
  • New Topic

Structure/Organization Issues  RSS feed

 
Edgar Cantu
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am new to Java and currently work in the IT field so learning Java is crucial. I am working on a project and I am not understanding how code needs to be organized. I understand I am receiving code errors due to the structure of a method within a method, however, everything I try causes a separate error to occur. I also need to write another method that will include a writeFile() output method that will include the information from user inputs. Please help, I am behind on this project currently and I am just not getting the understanding I want.

Thanks.


 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edgar Cantu wrote:I am receiving code errors due to the structure of a method within a method, however, everything I try causes a separate error to occur.


TellTheDetails. Are you getting compiler errors? If so, can you show us what this are?

Henry
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can define a class within a class but you can't define a method within a method.
Also, use code tags when posting code.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I have added the code tags, and don't they make the code look better. Unfortunately they show some more things. There are lines far too long, some of which I have broken so you can see how to do it. There are also too many declarations; you should stick to one per line. Lines that long can cause serious confusion, particularly with multiple declarations.
There is also inconsistent indentation. We have some suggestions ourselves. One thing is that except in array initialisers you should never have more than one { or } on the same line. Look at line 11. If you go through the class and indent everything consistently, I think you will find line 12 is not in the workinggarVideo method. Even were that in the method, there is much too much code there for one method. That should be divided into multiple methods. And why have you marked the workinggarVideo method static? If you cannot explain why you used static I always presume it is a serious mistake.
Why are you using option pane for user input? That is a very old‑fashioned style of programming.
Avoid System#exit. It is probably acceptable in a simple one‑threaded application but it can cause serious damage in a multi‑threaded program.

Start by writing down what you are trying to do. There will be lots of things If one of them is, “verify phone number”, then you probably need a verifyPhoneNumber method. As a general rule there should be one method for each thing you are trying to do.
 
Knute Snortum
Sheriff
Posts: 4288
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect this is one of the problems:


This looks like half a constructor and half a main() method. You have both void and String as a return type, which is illegal. I suspect you want this:

But there's still problems. If you want a main() method that executes at the beginning of the program, it needs to be called "main". Calling it "workinggarVideo" makes it look like a constructor. So we have:

But there's still a problem. You have opening and closing braces, so the body of main() is empty. Then you have an opening brace by itself. This looks like an initializer -- probably not what you meant. So now we have:

I suspect this is what you meant to write. After fixing this, you may see other errors, but this will get you started.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!