• Post Reply Bookmark Topic Watch Topic
  • New Topic

My business management program  RSS feed

 
jon ninpoja
Ranch Hand
Posts: 291
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,

i feel i have been jumping around a bit....and dont seem to finish projects i start
i started this one a while ago and have got further without assistance than i thought i would get (though its still not that far)

anyway,i have re-written a little (or started anyway) a mini business management program
its very simple to begin with...it presents you with a menu that lets you add a company name and how much money
they owe you (a very useful feature) i will present the code then i have (as usual) a few questions.

please feel free to criticize the code and also let me know of design flaws...how i should rather be structuring things instead etc etc

thanks for the help guys!!!

main:



menu:



company:



now after entering the amount i would like a company object to be created
one that has the name that was entered or not necessarily,just contain the data the user entered

im sure it has to be put into an array list...should i have a method called existingCompanies? and have the method called every time
the menu item is selected,then there is deleting/editing

is this structure ok,or am i coding into a brick wall!!!

cant wait for feedback


 
jon ninpoja
Ranch Hand
Posts: 291
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it possible to make objects on the fly that hold different value?
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but you'll need to structure your classes differently.  Company class should not contain prompts to the console and keyboard input.  What if you want to create a GUI or a web app?  Have another class get the input from the console and pass those data to the constructor of Company.

Now you can use Company like this:
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure what you mean about creating new objects on the fly, but I think yes.
You have not got a constructor for your Company class. That means its instances can live in an inconsistent state for ever. There is no guarantee that users will ever call those methods.
And those methods are a bad example of repeated code. Find out what DRY means. And then you will see why you shou‍ld put that sort of keyboard input code into a separate utility class.
 
jon ninpoja
Ranch Hand
Posts: 291
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
knurt is the main method fine for this? or should there be another class called say ... Assemble or something else

campbell will read about DRY...never heard of it before...

thanks guys

will rebuild over the weekend...
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jon ninpoja wrote:knurt is the main method fine for this? . . .
knurt? Do you mean Knute?
The main method looks all right. But why are you going straight into reading passwords? That might be part of the application, but there shou‍ld surely be a method to run the application which might include asking for a password. String#equals is of course a very low‑security way to check a password.
 
jon ninpoja
Ranch Hand
Posts: 291
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Campbell

it wasnt a serious thing,i know there are very secure ways to encrypt/hide passwords etc...was just a little exercise
i suppose if i was using a database or something i could use a far more secure way to hide passwords

 
jon ninpoja
Ranch Hand
Posts: 291
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi campbell,

"And those methods are a bad example of repeated code. Find out what DRY means. And then you will see why you shou‍ld put that sort of keyboard input code into a separate utility class."

so should there be a separate class to control all of this...sorry i dont really understand,can you please elaborate a bit...i feel this is very important

 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think what Campbell is talking about is that you have several places in your code where you do this:

You could make this a method and then call the method instead of copying and pasting or rewriting code.
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you could benefit from having a kind of driver method that you call from main() like this:
 
jon ninpoja
Ranch Hand
Posts: 291
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but isnt this a method?
public static void printMainMenu

handling the  its input...how should it rather be done...i really need and value your guys instruction
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess this could be the driver called from main:

 
jon ninpoja
Ranch Hand
Posts: 291
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry knute,

i dont really understand your reply...
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right now you have this for your "driver" class ("driver" = the class that puts everything in motion):

There are problems with this.  You create an object from the class Menu and then call enterPassword() on it.  What does a password have to do with the menu?  Second, it looks like all your program does is get a password.

So I was suggestion ways to make your "driver" class (MainMethod, also a bad name) look more like what you're doing.  First, what to call the driver class?  What about BusinessManagement?  That tells you what the program does.  Now, it's traditional and a good idea to have almost nothing in your main() method.  It should just start a method that shows you on a very high level what the program does.  Let's call that method run().  So far we have:

So what should be in run?  Well, you should be able to basically say what's going to happen in the program. So I suggested:

The above is called pseudocode.  It's not concerned about strict syntax, just the overall flow of the program.

You'd have to change two of your methods for this to work: getPassword() would need to return whether it got a valid password (a boolean) and displayMenu() would need to return whether the user picked Exit (also boolean).

Does this give you a place to start working?
 
jon ninpoja
Ranch Hand
Posts: 291
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
aaaaay thanks Knute Snortum

will re write from scratch when i get a chance...really thanks...better to get out of bad habits/design early

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!