• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

save and load

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 954
4
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what is your problem? Have you struck somewhere? What is your question??
 
Sheriff
Posts: 7123
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Can you show us what you've tried so far?
 
Marshal
Posts: 8515
610
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:






 
Saloon Keeper
Posts: 9720
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to use this method but don't know to relate to my Library class.

 
Carey Brown
Saloon Keeper
Posts: 9720
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 9720
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 9720
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Methods inside Library

 
keiriso samaron
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 9720
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I put the following arguments:
Please bear in mind, I am in a first java programming course.

 
Carey Brown
Saloon Keeper
Posts: 9720
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Oh. Hi guys! Look at this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic