I need to store data from a text file into an object array then store the object array into a linked list using Java Example of file im trying to convert: //String  //Int  //Double  //Double  //Int Joe   101   17.2  10.0  4 Alex    97  15.3  12.5  7 Maria  85  16.4   18.2   9 Steve  153  23.5  16.3  8

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I need to store data from a text file into an object array then store the object array into a linked list using Java

Example of file im trying to convert:

//String  //Int  //Double  //Double  //Int

Joe   101   17.2  10.0  4

Alex    97  15.3  12.5  7

Maria  85  16.4   18.2   9

Steve  153  23.5  16.3  8

Expert Solution
Step 1
  • Introdution :

Algorithm:

1. Create an object class with the data fields from the text file.
2. Read the text file line by line and store each line into an array.
3. Create an object from the object class with the values from the array.
4. Store the object into an array.
5. Create a linked list.
6. Iterate through the object array and add each object to the linked list.

  • Explanation of Code:

The object class is used to create objects that store the data from the text file. The fields of the object class are the same as the data fields in the text file. Then the text file is read line by line and each line is stored in an array. An object is created with the values from the array and stored in an array of objects. Then a linked list is created and the array of objects is iterated through, adding each object to the linked list.

Parsing a Text File: Parsing a text file is the process of reading the file line by line and extracting the data from it. To parse a text file you need to use a library such as Apache Commons IO or Scanner.

Creating an Object Array: Object arrays are used to store multiple objects in one array. To create an object array, you need to use the new keyword followed by the object type and the array size. For example, Person[] people = new Person[4];

Storing Objects in a Linked List: Linked lists are data structures used to store objects in a linked list format. To store an object in a linked list, you need to create a Node object and set the data field to the object you want to store. Then you need to add the Node to the linked list.

Java Programming Language: Java is an object-oriented programming language used to write programs. To write a program in Java you need to use classes, methods, and variables. Java also provides data structures such as arrays, linked lists, and maps to help you store and manipulate data.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education