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 + ""; } }

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 Answer

Want to see the step-by-step answer?

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.
Tagged in
Engineering
Computer Science

Databases

Data Structures

Related Computer Science Q&A

Find answers to questions asked by students like you.

Q: Suppose that you traverse the binary search tree in write the data item in each node visited to a fi...

A: Solution is in Step 2. 

Q: The Code must be in Java   Write a program to calculate the following for each integer from 0 to 35:...

A: Actually, program is a executable software that runs on a computer.

Q: I need help in this program. I am trying to create a pep/9 assembly program which uses do while loop...

A: The Pep/8 uses a 16-bit address bus, capable of addressing 65,536 bytes Internal Registers: The CPU ...

Q: public class Recursive{ public static void main(String[] args){ System.out.println("Summation of 5 S...

A: The given problem is to be solved in java language with recursion methods. A recursive method calls ...

Q: This question is based on the following relation and sample data, where Employee Social Security Num...

A: Actually, database is a used to stored the data.

Q: Find the attached file.

A: Class defitnion:  Class is a user-defined data type that contains the data members and member functi...

Q: Please use C++ code and only use the libraries &lt;iostream&gt; and &lt;fstream&gt;.  Thank you!

A: Before beginning the program, make sure to have both input file, rot13.txt, and the output file, rot...

Q: Write a code in python. Write down only the methods that are required; testers are not required. Co...

A: Answer in step2

Q: I am receiving a NameError even though I though I had defined 'randomInt'. How would I remove this e...

A: The reason you are getting this error is because print function is in the class and not in the funct...

Q: Which of the following about dictionaries is false? A) Keys need to be unique B) Values need to be u...

A: Answer in step2

Q: In Python When analyzing data sets, such as data for human heights or for human weights, a common st...

A: n = int(input("Enter the number of integers in the data set: "))list = [] print("Enter the", n, "num...

Q: Let's make the relationship between shows and networks N:N (a many-to-many relationship), i.e. each ...

A: Junction table is used while dealing with many-many relationships in SQL database. Example for many ...

Q: Describe the format of the ALTER TABLE command to add new column.

A: While creating a table in RDBMS, we create a table by specifying all the constraints and columns usi...

Q: i) Have a look at the following piece of code and state and explain the output.   #include &lt;stdio...

A: Note: Since you have posted a question with multiple subparts in the same request, we will solve the...

Q: What is a palette? What is the advantage of using a color palette?

A: The, answer has given below:  

Q: What happens when you add an entry into position 4 into a List? Select one: a. If the List has 4 or ...

A: The answer given below:

Q: During the past year, Howard Industries has experienced excessive employee turnover in their IT func...

A: Even with highly sophisticated algorithms and modern supercomputers, there are models with just a fe...

Q: Question 1: pertains to the Cherokee School District scenario below. The school board for the Cherok...

A: mixed-integer programming (MIP) problem is one where some of the decision variables are constrained ...

Q: 2 When using binary search, the linear list must be

A: Please find the answer below :

Q: Using Python, answer the following

A: The question asks designing the 2 classes named Kingdom and CourtJester as described. The class Cour...

Q: Given the following business scenario, create a Crow's Foot ERD using a specialization hierarchy if ...

A: Given: An organization requires arranging employees and their insurance dependents' details in prope...

Q: NEED HELP WITH PYTHON CODE. AND PLEASE PROVIDE DETAILS ON HOW AND WHAT DID YOU USE FOR YOUR WORK SEP...

A: Actually, program is a executable software that runs on a computer.

Q: Which of the following statements is false?     A work breakdown structure is a hierarchical s...

A: Step 1:- Given:-Identify the false statement (a)A resource breakdown structure is a hierarchical str...

Q: Write a Java program that simulates a meeting reservation system. The program shall allow the user ...

A: Actually, java is a object oriented programming language. It is a platform independent.

Q: 2. Text statistics. Write a function text_stats(text) that returns a single dictionary with the foll...

A: Since You have not specified the programming language, we will be solving this question in python. #...

Q: Using the descriptions of the attributes given in the figure, convert the ERD shown in Figure P6.1 i...

A: To obtain the Dependency Diagram in at least 3NF, the given relation needs to be converted into 3NF....

Q: convert the following c++ program into pep/9 assembly language. please send the screen shot of runni...

A: #include &lt;iostream&gt;using namespace std;int main(){    int x,i;    cout&lt;&lt;"enter a number:...

Q: Hi I am struggling with the loops and printing to screen

A: Java program:   //importing essential java package import java.util.Arrays;   //main class public cl...

Q: Andrew likes the topic of strings a lot and tries to solve as many questions as possible on this top...

A: You haven't mentioned the language. So, we are providing the solution in c. Program code: #include&l...

Q: In which of the following scenarios is it appropriate to apply a named range? a. When using -COUNTIF...

A: Answer in step2

Q: Write pseudocode and Python code  Design a program that computes pay for employees. Allow a user to ...

A: all_detail = []while True: name = input('\nEnter Employee name: ') if '-' in name: prin...

Q: BR MAIN FORMAT Complete the following C++ programs into Pep/9 assembly language: 1) int main(){  int...

A: 1) Answer  __gthread_key_delete(int):        str     fp, [sp, #-4]!        add     fp, sp, #0       ...

Q: Q1. Given the following expression: 8 + b – c * (x * 2 ^ 6) – m / 7 [Show how the expression is conv...

A: Objective: An infix expression is given and the expression should be converted into the postfix expr...

Q: Which line of code would correctly retrieve the value stored in row 0, column 0 in a 2-D array calle...

A: Two-Dimensional Array Definition: Two-dimensional arrays are defined as arrays of arrays. Also writ...

Q: Computer Science Question

A: file = open("data.txt", "w+") while True:    name = input("Enter employee name or Enter to quit ")  ...

Q: Question

A: An arithmetic expression tree is a tree representation of the operators and operands in a binary for...

Q: TableAA.java Write a program that will store a multiplication table in a 2-D array. The user will en...

A: ⦁ Drawn table from given input using scanner. ⦁ 2 dimensional which show number of columns and rows ...

Q: What would happen when the following code is run and why? int num[] = {2, 4, 6, 8}; System.out.print...

A: An array in Java is a group of variables of the same type. An array is a reference type variable, bu...

Q: Question is to expand on current code.(program written in C) (3) Extract the two words from the inp...

A: The current C program is 100% correct. I tried running it to C compiler and it is working absolutely...

Q: program to be written in c   1) Prompt the user for a title for data. Output the title.  Ex: Enter ...

A: Actually, program is a executable program that runs on a computer.

Q: 24. What sequence of nodes from the tree A B DE F G would be printed if the following recursive proc...

A: The given recursive procedure is used for inorder traversal of a tree. The following will be printed...

Q: Note:- Study this program and follow the given instruction and type execute the code and also give o...

A: PROGRAM: //Header files import java.util.Scanner; import java.io.*;   //Defining class         publi...

Q: answer in c++

A: Introduction of the program: The C++ program takes an integer from the user as input and then the C+...

Q: JAVA assignment: Exercise 1: Implement the class Student as presented by the following UML diagram: ...

A: public class Student { private String name; private int id; private char gender; private String addr...