public static void main(String[] args) { List courses = getCourseList(); List students= getStudents(); ...But I need both lists to be joined together so that I can use a System.out.println to display both lists together/at the same time. Is there a way to do that? Here are my java files: testStudent.java import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class testStudent { public static void main(String[] args) { List courses = getCourseList(); List students= getStudents(); for(Student st:students) { System.out.println(st); } } public static List getStudents() { List returnList = new ArrayList(); BufferedReader reader; try { reader = new BufferedReader(new FileReader("ClassesData.dat")); String line = reader.readLine(); while (line != null) { Student tempStudent = new Student(); tempStudent.setCourseId(Integer.parseInt(line)); line = reader.readLine(); tempStudent.setClassName(line); line = reader.readLine(); tempStudent.setCredits(Integer.parseInt(line)); line = reader.readLine(); tempStudent.setStudentName(line); line = reader.readLine(); tempStudent.setMajor(line); line = reader.readLine(); tempStudent.setGrade(line); line =reader.readLine(); returnList.add(tempStudent); if(tempStudent.getGrade().equals("A")) { tempStudent.setComment("Great job!"); } else { tempStudent.setComment("-"); } } reader.close(); } catch (IOException e) { e.printStackTrace(); } return returnList; } public static List getCourseList() { List returnList = new ArrayList(); BufferedReader reader; try { reader = new BufferedReader(new FileReader("CoursesData.dat")); String line = reader.readLine(); while (line != null) { Course tempCourse = new Course(); tempCourse.setCourseId(Integer.parseInt(line)); line = reader.readLine(); tempCourse.setInstructorId(line); line = reader.readLine(); tempCourse.setRoomId(line); line = reader.readLine(); returnList.add(tempCourse); } reader.close(); } catch (IOException e) { e.printStackTrace(); } return returnList; } } Student.java public class Student { private String studentName; private int courseId; private String major; private String className; private String roomId; private String instructorId; private String grade; private int credits; private String comment; public Student() { super(); } public Student(String studentName, int courseId, String major, String className, String roomId, String instructorId, String grade, int credits, String comment) { super(); this.studentName = studentName; this.courseId = courseId; this.major = major; this.className = className; this.roomId = roomId; this.instructorId = instructorId; this.grade = grade; this.credits = credits; this.comment = comment; } public void setStudentName(String studentName) { this.studentName = studentName; } public String getStudentName() { return studentName; } public void setCourseId(int courseId) { this.courseId = courseId; } public int getCourseId() { return courseId; } public void setMajor(String major) { this.major = major; } public String getMajor() { return major; } public void setClassName(String className) { this.className = className; } public String getClassName() { return className; } public void setRoomId(String roomId) { this.roomId = roomId; } public String getRoomId() { return roomId; } public void setInstructorId(String instructorId) { this.instructorId = instructorId; } public String getInstructorId() { return instructorId; } public void setGrade(String grade) { this.grade = grade; } public String getGrade() { return grade; } public void setCredits(int credits) { this.credits = credits; } public int getCredits() { return credits; } public void setComment(String comment) { this.comment = comment; } public String getComment() { return comment; } public String toString() { return "Student Name: " + studentName + " || Course ID: " + courseId + " || Class Name: " + className + " || Room ID: " + roomId + " || Instructor ID: " + instructorId + " || Grade: " + grade + " || Credits: " + credits + " || Comments: " + comment + ""; } } Course.java public class Course { private int courseId; private String instructorId; private String roomId; public Course() { super(); } public Course(int courseId, String instructorId, String roomId) { super(); this.courseId = courseId; this.instructorId = instructorId; this.roomId = roomId; } public int getCourseId() { return courseId; } public void setCourseId(int courseId) { this.courseId = courseId; } public String getInstructorId() { return instructorId; } public void setInstructorId(String instructorId) { this.instructorId = instructorId; } public String getRoomId() { return roomId; } public void setRoomId(String roomId) { this.roomId = roomId; } public String toString() { return "Course ID: " + courseId + " || Instructor ID: " + instructorId + " || Room ID: " + roomId + ""; } }

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

Hello. I am trying to figure out a way to print out two lists at the same time. I have my lists written as such:

public static void main(String[] args)
{
List<Course> courses = getCourseList();
List<Student> students= getStudents();


...But I need both lists to be joined together so that I can use a System.out.println to display both lists together/at the same time. Is there a way to do that?

Here are my java files:

testStudent.java

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class testStudent
{
public static void main(String[] args)
{
List<Course> courses = getCourseList();
List<Student> students= getStudents();
for(Student st:students)
{
System.out.println(st);
}
}


public static List<Student> getStudents()
{
List<Student> returnList = new ArrayList<Student>();
BufferedReader reader;
try
{
reader = new BufferedReader(new FileReader("ClassesData.dat"));
String line = reader.readLine();
while (line != null)
{
Student tempStudent = new Student();
tempStudent.setCourseId(Integer.parseInt(line));
line = reader.readLine();
tempStudent.setClassName(line);
line = reader.readLine();
tempStudent.setCredits(Integer.parseInt(line));
line = reader.readLine();
tempStudent.setStudentName(line);
line = reader.readLine();
tempStudent.setMajor(line);
line = reader.readLine();
tempStudent.setGrade(line);
line =reader.readLine();
returnList.add(tempStudent);
if(tempStudent.getGrade().equals("A"))
{
tempStudent.setComment("Great job!");
}
else
{
tempStudent.setComment("-");
}
}
reader.close();
}
catch (IOException e)
{
e.printStackTrace();
}

return returnList;
}


public static List<Course> getCourseList()
{
List<Course> returnList = new ArrayList<Course>();
BufferedReader reader;
try
{
reader = new BufferedReader(new FileReader("CoursesData.dat"));
String line = reader.readLine();
while (line != null)
{
Course tempCourse = new Course();
tempCourse.setCourseId(Integer.parseInt(line));
line = reader.readLine();
tempCourse.setInstructorId(line);
line = reader.readLine();
tempCourse.setRoomId(line);
line = reader.readLine();
returnList.add(tempCourse);
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
return returnList;
}
}

Student.java

public class Student
{
private String studentName;
private int courseId;
private String major;
private String className;
private String roomId;
private String instructorId;
private String grade;
private int credits;
private String comment;


public Student()
{
super();
}

public Student(String studentName, int courseId, String major, String className,
String roomId, String instructorId, String grade, int credits, String comment)
{
super();
this.studentName = studentName;
this.courseId = courseId;
this.major = major;
this.className = className;
this.roomId = roomId;
this.instructorId = instructorId;
this.grade = grade;
this.credits = credits;
this.comment = comment;
}

public void setStudentName(String studentName)
{
this.studentName = studentName;
}

public String getStudentName()
{
return studentName;
}


public void setCourseId(int courseId)
{
this.courseId = courseId;
}

public int getCourseId()
{
return courseId;
}


public void setMajor(String major)
{
this.major = major;
}

public String getMajor()
{
return major;
}


public void setClassName(String className)
{
this.className = className;
}

public String getClassName()
{
return className;
}


public void setRoomId(String roomId)
{
this.roomId = roomId;
}

public String getRoomId()
{
return roomId;
}


public void setInstructorId(String instructorId)
{
this.instructorId = instructorId;
}

public String getInstructorId()
{
return instructorId;
}


public void setGrade(String grade)
{
this.grade = grade;
}

public String getGrade()
{
return grade;
}


public void setCredits(int credits)
{
this.credits = credits;
}

public int getCredits()
{
return credits;
}


public void setComment(String comment)
{
this.comment = comment;
}

public String getComment()
{
return comment;
}


public String toString()
{
return "Student Name: " + studentName + " || Course ID: " + courseId + " || Class Name: " + className
+ " || Room ID: " + roomId + " || Instructor ID: " + instructorId + " || Grade: " + grade + " || Credits: " + credits
+ " || Comments: " + comment + "";
}
}

Course.java

public class Course
{
private int courseId;
private String instructorId;
private String roomId;

public Course()
{
super();
}

public Course(int courseId, String instructorId, String roomId)
{
super();
this.courseId = courseId;
this.instructorId = instructorId;
this.roomId = roomId;
}

public int getCourseId()
{
return courseId;
}

public void setCourseId(int courseId)
{
this.courseId = courseId;
}

public String getInstructorId()
{
return instructorId;
}

public void setInstructorId(String instructorId)
{
this.instructorId = instructorId;
}

public String getRoomId()
{
return roomId;
}

public void setRoomId(String roomId)
{
this.roomId = roomId;
}

public String toString() {
return "Course ID: " + courseId + " || Instructor ID: " + instructorId + " || Room ID: " + roomId + "";
}

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Lists
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
  • SEE MORE 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