Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

save and load  RSS feed

 
keiriso samaron
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there,
I need help with the following code. I would like to add a method that will save items and load them when the program is rerun.

 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what is your problem? Have you struck somewhere? What is your question??
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Can you show us what you've tried so far?
 
Liutauras Vilda
Marshal
Posts: 4642
318
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before you specify exact problems you are facing, there are some other issues needs to be fixed.

1. Fields are not private (items, keys). They really should be.
2. Methods names are poorly chosen and not self explaining.
3. Comments are added in addition to explain what methods suppose to do, unfortunately these are not descriptive too and there are too many of them.

Try to come up with self explaining method names, so you wouldn't need current comments.
 
keiriso samaron
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there,

Thank you for your quick response. I am trying to program a library application. I have three classes, a Manual class that hold item, a Library class that hold items and Menu class with a switch cases. What I am trying to achieve is to be able to have a switch case that will save the items. So, I need to have a method that will save items. Please see three classes under:






 
Carey Brown
Bartender
Posts: 2996
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would change
to
Then your load would be
and save would be
Load and save would probably be best done using serialization. Give it a try.
Alternatively you could use a flat file with each line containing a Manual with it's fields separated by some delimiter.
 
keiriso samaron
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your response. I need some help with writing of the methods. I will appreciate if you could give a example.

 
keiriso samaron
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to use this method but don't know to relate to my Library class.

 
Carey Brown
Bartender
Posts: 2996
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why "loadScript" and not just "load"?

Why load a specific refNo? Why not load all of them as a Library.

Likewise, save the entire library as a whole.

What is a 'lib'?

Why cast to a Library when it appears that you're reading a Manual of a given refNo?
 
Carey Brown
Bartender
Posts: 2996
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your Library class needs two new methods: load(), and save(). Both of which should not need any arguments.
 
keiriso samaron
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Carey,
I don't understand what you mean with no argument. Do I need to create the methods as follow:
 
Carey Brown
Bartender
Posts: 2996
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Methods inside Library

 
keiriso samaron
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added the two methods in Library, and created the options but not getting the results when saving and loading.
 
Carey Brown
Bartender
Posts: 2996
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did you put in the body of those two methods?
How are you calling them?
 
keiriso samaron
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I put the following arguments:
Please bear in mind, I am in a first java programming course.

 
Carey Brown
Bartender
Posts: 2996
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
keiriso samaron wrote:I put the following arguments:
Please bear in mind, I am in a first java programming course.


See comments I added in above code.
Both Library and Manual will need to 'implement' Serializable, as well as provide

For now I'd just hard code a file name.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!