• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

making object arraylist from file.txt

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello I'm trying to remake an object from a text file. I think I got most of it to work but I don't know how to make a Boolean from a String or LocalDate from a String. Is it even possible?

 
Sheriff
Posts: 8890
638
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi matthew,

What you are saying, you want [1] read a file, [2] create an object containing read information. Right?

Did you create a class, which defines a blueprint for an object you want to create?

Your method importFile() doesn't make sense, in short - it isn't correct, over complicated and does a lot stuff which aren't related with method's name.

Methods supposed to do one and only one thing. So you importFile() method should be probably one liner if we were know what import means.

Is it school's assignment? In case yes, can we see some of instructions you have been given?
 
Liutauras Vilda
Sheriff
Posts: 8890
638
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

matthew reid wrote:Boolean from a String or LocalDate from a String. Is it even possible?


Yes, that is possible. But probably you first need to create a class which could hold all that information.

I see you have SaleOffer. Actually feels like you have too few classes. Because if class has more than 3-5 parameters, it is a good indication that design is flawed.

Can you please post SaleOffer class in full here?
 
matthew reid
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Objectives

• Develop a Java GUI application using layout managers
• Develop an application that uses two or more classes
• Read and/or write from/to text files
• Use search algorithms and/or sort algorithms
• Use ArrayList or LinkedList or any other data structure

General

In your assignment 2, you can continue to develop the Java GUI application that you have created in your assignment 1. If you would like to modify the codes that you have submitted in your assignment 1, you are free to do so. You can adopt any layout patterns that are suitable for the requirements of the application in your assignment 2.  

Assignment Task specification

CQRE has requested you to help them finalize the property sale deal based on the following rules:
1. Identify the purchase offer that has the highest offered amount for a property sale offer.
2. The identified highest offered amount should be at least 90% of the seeking price of the sale offer.
3. In case of matching amount of purchase offers, the decision is up to the seller.
4. Purchase offers are not allowed after a property sale is finalized.

CQRE also wants to view the commission amount receivable for each of the property sale that has been finalized.  Hence, you need to store the relevant details in text file(s) and also to provide appropriate searching facilities to display the details of finalized property sale(s) which have been assigned/managed by the given employee.

Hence in addition to the requirements of the assignment 1, the software application that you will develop in assignment 2 should perform all of the following:

1. When the application is started, it should read the details of the property sale offers from the existing text file(s) and display the latest property sale offer.
2. The application should provide control(s) to finalize the property sales.
3. The application should provide details of all finalized property sales including the commission amount receivable.


4. The application should provide necessary controls to search and display the details of finalized property sales which have been assigned/managed by a given/selected employee (details to be obtained from/ selected by the user). If the search criterion is not met then an appropriate message has to be displayed.
5. The application should have the facility to append/save the details of new property sale offers and respective purchase offers and finalized status (finalized or not) in relevant text file(s).

In order to include these additional changes in the Java GUI application, you may need to do any or all of the following:
• develop additional Java classes
• extend the existing Java classes that you have developed for your assignment 1
• implement newly created interface(s)

For the assignment 2, you may need additional controls and you are encouraged to develop your own GUI layout.  Please note that you can create the required text file(s) through your application program for storing the data initially. During the subsequent run the same file(s) can be used by your application appropriately.


 
Liutauras Vilda
Sheriff
Posts: 8890
638
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Why SaleOffer extends Property? SaleOffer IS-A Property? What is that Property?

And please tell now, where exactly your problem is?

 
Ranch Hand
Posts: 595
6
jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a thought on this. Isn't this the exact use case where we can directly use serialization?

Serialize to file and then read the file and load the object.
 
Liutauras Vilda
Sheriff
Posts: 8890
638
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why propAddress, propType propArea, numRoom, numToilet numGarage are in SaleOffer class and not in Property?
 
matthew reid
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:
Why SaleOffer extends Property? SaleOffer IS-A Property? What is that Property?



should I have all saleOffers and purchaseOffers all in the property class instead of having each class

And please tell now, where exactly your problem is?



my problem is when it reads the file the string cant be converted to Boolean and I cant figure out the date



Just a thought on this. Isn't this the exact use case where we can directly use serialization?



never heard of this before so I didn't know

Why propAddress, propType propArea, numRoom, numToilet numGarage are in SaleOffer class and not in Property?



these are in the property class



 
s ravi chandran
Ranch Hand
Posts: 595
6
jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check this link: Serialization

This should fulfill your requirement.
 
Bartender
Posts: 10893
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

matthew reid wrote:


Do you know how to look up methods in Javadocs API ?  If not, it is a crucial step in learning to code in Java.

This error points to the nextLocalDate() method of Scanner and says it's not found.

You can look at all the methods available to a Scanner HERE. Notice nextLocalDate() is not one of your options. You'll probably need to read the date in as a string and convert it. You'll need to know the format of the string.

P.S. When posting errors like this be sure to enclose them in Code tags otherwise the little caret (^) pointer won't line up.
 
Carey Brown
Bartender
Posts: 10893
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

s ravi chandran wrote:Check this link: Serialization

This should fulfill your requirement.


This is a good suggestion but it depends on the wording of the requirements. If you are required to read/write a TEXT file, then serialization won't be an option. If on the other hand the requirements just say a FILE, then serialization would be an option. Serialization produces a binary file, not a text file.

Edit: For a novice, a delimited text file is probably easier to understand. Write out the fields as strings separated by tabs ('\t''). Then when you read in the file you can set up a Scanner to look for the tabs, or read line by line and use String.split("\t") to breakout the fields.
 
s ravi chandran
Ranch Hand
Posts: 595
6
jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:
This is a good suggestion but it depends on the wording of the requirements. If you are required to read/write a TEXT file, then serialization won't be an option. If on the other hand the requirements just say a FILE, then serialization would be an option. Serialization produces a binary file, not a text file.

Edit: For a novice, a delimited text file is probably easier to understand. Write out the fields as strings separated by tabs ('\t''). Then when you read in the file you can set up a Scanner to look for the tabs, or read line by line and use String.split("\t") to breakout the fields.



Got the point. I was just focussing on the ease of converting binary data to objects.

Certainly for beginners, the method that they find easy to understand should be used.
 
Sheriff
Posts: 7125
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

Do you know how to look up methods in Javadocs API ?  If not, it is a crucial step in learning to code in Java.  


There are two ways I do this.

1) If I'm looking for Scanner, I Google java 8 scanner and the API doc link is usually the first.
2) I start at https://docs.oracle.com/javase/8/docs/api/ and look under the All Classes frame.
 
Villains always have antidotes. They're funny that way. Here's an antidote disguised as a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic