Solved Homework: Question: 26. Write a program to read a list of students from a file and create a list. The program should …

I need a program that solves this program
26. Write a program to read a list of students from a file and create a list. The program should use a linked list for implementation. Each node in the linked list should have the students name, a pointer to the next student, and a pointer to a linked list of scores. There may be up to four scores for each student. The structure is shown in Figure 5-33 Students Albert Einstein-5267-63 Steve Abrew. Sarah Trapp FIGURE 5-33 Data Structure for Project 26

26. Write a program to read a list of students from a file and create a list. The program should use a linked list for implementation. Each node in the linked list should have the student’s name, a pointer to the next student, and a pointer to a linked list of scores. There may be up to four scores for each student. The structure is shown in Figure 5-33 Students Albert Einstein-5267-63 Steve Abrew. Sarah Trapp FIGURE 5-33 Data Structure for Project 26

Expert Answer

answers

Solution: because the format of file is not given so based upon the format shown in figure I am considering the file in below format as input

InputTo Program

student.txt

Albert Einstein,56,89,90
Steve Abrew,45,78,56
Russel Peter,56,34
Sarah Trapp,23

Code:

package com.tree;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class StudentLinkedList {
Student head;

public void create(String fileName) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new FileReader(new File(fileName)));
String line = null;
while ((line = bufferedReader.readLine()) != null) {
String[] array = line.split(“,”);
for (String data : array) {
// this is for very first node
if (head == null) {
Student student = new Student();
student.studentName = data;
head = student;
continue;
} // this for second node onward
else {
int data1 = 0;
try {
// because first word of file is name that means its a
// new student then in this case it wont be able to
// parse string then we can create student object in
// catch conditon and linked to previous student
data1 = Integer.parseInt(data);
// if this is first node the score wont be there then
// add it
if (head.score == null) {
Score score = new Score();
score.data = data1;
head.score = score;
} // if score is already added then link all score to
// other score for that student
else {
// this condition for very first student and linking
// all his score
Student nextStudent = head;
if (nextStudent.next == null) {
Score temp = nextStudent.score;
while (temp.next != null) {
temp = temp.next;
}
Score score = new Score();
score.data = data1;
temp.next = score;
} // this condition is for other students who are
// linked to first student onward and their
// score respectively
else {
while (nextStudent.next != null) {
nextStudent = nextStudent.next;
}
Score temp = nextStudent.score;
if (temp == null) {
Score score = new Score();
score.data = data1;
temp = score;
nextStudent.score = temp;
} else {
while (temp.next != null) {
temp = temp.next;
}
Score score = new Score();
score.data = data1;
temp.next = score;
}
}
}
} catch (Exception e) {
Student temp = head;
while (temp.next != null) {
temp = temp.next;
}
Student student = new Student();
student.studentName = data;
temp.next = student;
continue;
}

}
}
}
}

// this is used to display record
public void displayRecord() {
Student student = head;
while (student != null) {
System.out.print(student.studentName + “:”);
Score score = student.score;
while (score != null) {
System.out.print(score.data);
score = score.next;
if (score != null)
System.out.print(“,”);
}
System.out.println(“n”);
student = student.next;
}
}

static class Student {
String studentName;
Score score;
Student next;
}

static class Score {
Score next;
int data;
}

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println(“Please provide file name with full path”);
String fileName = scanner.nextLine();
StudentLinkedList list = new StudentLinkedList();

try {
list.create(fileName);
list.displayRecord();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

Output

Please provide file name with full path

student.txt
Albert Einstein:56,89,90

Steve Abrew:45,78,56

Russel Peter:56,34

Sarah Trapp:23

if your file is outside workspace somewhere in the other directory then give full path as input including file name if you are working in eclipse then put your txt file inside the project as shown in below

, practiseproject 4静src >串com.graph.matrix D>串com.tree JRE System Library [JavaSE-18] 目student.txt wordcount.txt wrestler.tt

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.

× How can I help you?