• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

GregorianCalendar to ArrayList

 
Ranch Hand
Posts: 36
Eclipse IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys. I've got a small bit of code i'm having trouble with. Here's the idea. The user has a JTextField to put a date into. Once they put in the date, it is
1) Checked to make sure it is actually a date
2) Converted into type gregordianCalendar
3) Stored in an ArrayList for the future part of the program

I'm having trouble converting from GregordianCalendar to Array List. Any Help?


The method transactions() looks like this:



The class Transaction looks like this


and the class TransactionType looks like this:
 
Marshal
Posts: 76395
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't return the transactions List from the transactions method. Return an unmodifiable copy, with this method. That way, nobody can get their hands on the transactions list and change the transactions. And change the declared type of the List (and return type for that method) to List<Transaction>. I also think you should make all the fields in the Transaction class final, again so nobody can change them. Your Transaction class will then need a constructor. Since GregorianCalendar is mutable, you would have to return a copy of the date from any getDate() method in the Transaction class. Again, to prevent anybody changing the details of the transaction.

Why have you got a return; statement in the catch block? You wold be better putting the reading part in a loop, so it will try again until a date is entered in the correct format.

You cannot change a Calendar object to a List. What you can do it set it as the field in the new Transaction object, and add that Transaction to the List.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic