• Post Reply Bookmark Topic Watch Topic
  • New Topic

Storing new users into Arraylist - saving data in txt  RSS feed

 
Mike dawn
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone
I need some help.

I have created this project and want to be able to add new members to my members arraylist,
store the input in a .txt file and load the new members after closing and opening the program.

can you help me?

https://www.dropbox.com/s/qw1dvr5v0sq42f3/Dolphin%20Club%20%285%29.zip?dl=0

Best Regards
Mikkel
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Please post your code here (and remember to UseCodeTags).
Many people are reluctant to click links to third-party web sites.
And they may be especially reluctant to download some zip file.
 
Mike dawn
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Member class







Active:







Eltie:


 
Mike dawn
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please help
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please use the code button; don't write tags by hand. I had to change highlight to code to get them to work. Don't use lots of blank lines; you usually only need one blank line at a time.
I am afraid that Member class has some serious problems in. I can only mention a few; there are bound to be more:-
  • When you inherit from a class, you never want to create new fields with the same name. I think ideally you should have no new public methods and no new fields, but that is often not achievable. You should have all the same fields in Active as in Member, and you need no new fields. Or very few new fields.
  • You should only write a constructor when you need it. Why have you got that no‑arguments constructor? That allows you to create a member with no name. You don't have members with no names, so you should not have Member objects with no names. That no‑arguments constructor should be deleted.
  • You have misunderstood getXXX methods. That get method with options is very brittle code, which will fail if you pass an argument with a tiny spelling error in. Use a separate get method for each field you wish to return.
  • Only ever return a String when it represents text. Never use a String to represent a number, date, or anything else.
  • Never use the == operator to compare Strings.
  • Give your setXXX methods void return type.
  • It is potentially dangerous to write (this) in the constructor.
  • I am afraid you are going to have to rewrite at least 50% of that code.

    You ought not to have a List of members in the Member class. There ought to be a Club class which has the List of Members.
     
    Campbell Ritchie
    Marshal
    Posts: 56598
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Mikkel Samuelsen wrote:please help
    Please read this.
     
    Winston Gutkowski
    Bartender
    Posts: 10575
    66
    Eclipse IDE Hibernate Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Mikkel Samuelsen wrote:please help

    With what?

    Your original post said "I [...] want to be able to add new members to my members arraylist, store the input in a .txt file and load the new members after closing and opening the program", but I see nothing that indicates you've actually tried it.

    However, here's a few tips for you - and they follow on from what Campbell already said:

    1. A class called Member should be exactly that - ONE member - and it should only contain methods that deal with ONE member.

    2. Since a text file will probably be made up of lines, each of which contains the information for ONE member, why not write a method that converts a Member to a String? And what method that is available to ALL classes does that suggest?

    3. Once you've written that, and you know it works, write another method that takes a String as created by the one from Step 2, and converts it back to a Member.

    And just one final point: When you're writing the method that converts a Member to a String, choose a simple format that can be easily converted back. One often-used format is "comma-delimited", ie:
      Joe Bloggs,37,25.00, ...
    but TBH I prefer to use something else as a delimiter - eg, a semicolon (;) or a 'pipe' (|), viz:
      Joe Bloggs|37|25.00| ...
    because you're far less likely to need to store anything that includes one of them as part of the data.
    And, as you can see, it's still quite "visual".

    You might also want to look up the 'split()' method in java.lang.String, because it'll be very useful when you come to write your "String-to-Member" method.

    HIH

    Winston

    PS: I've broken up some of the lines in your code because they were far too long. Please read the link before posting any more. Thanks.
     
    Don't get me started about those stupid light bulbs.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!