+ 1

Can anyone help me with this program?

A real estate company keeps in a text file information about properties ( house, apartment, and land)and their prices. Each line in this file is of the following form: property_id property_type price (e.g. 12123 apartment 600000). Note that the file is space delimited (one space between each field and the next one). Write a program that reads the information from this file and calculates the following totals then write them in another file. total price for houses apartments lands

23rd Jul 2018, 4:14 PM
Ibrahim Kadri
Ibrahim Kadri - avatar
2 ответов
0
//I would use the Scanner class with the File as input: File f = new File("path/filename.txt"); Scanner scan = new Scanner(file); //While the end of the File is not reached you can read out the data and store it in variables or Arrays: int result = 0; while(scan.hasNext()){ int price = scan.next(); result += price; } //write the result to a file (using PrintWriter): http://www.baeldung.com/java-write-to-file //remember to use try-catch Blocks when working with files but your IDE should suggest them anyway. This is one way to do it obviously there are many more and better ways.
23rd Jul 2018, 9:48 PM
lechickenburGER
lechickenburGER - avatar
0
lechickenburGER thank you
24th Jul 2018, 3:51 AM
Ibrahim Kadri
Ibrahim Kadri - avatar