Question: *** Write a Java programm*** This assignment will have you working with Collections and reading in another text file. This time you will identify the

*** Write a Java programm*** This assignment will have you working with Collections and reading in another text file. This time you will identify the people form the text file that fit in the following criteria: Those who took CS210, those who took CS211, those who took CS210 or CS211, those who took CS210 and CS211, those who took CS210 but not CS211, and finally those who took CS210 but not CS210. The text file consists of a list of students, theirs names, and the classes they took.

---------------student.txt-----------

cs211 John cs211 William cs211 Susan cs211 Jack cs211 Jennifer cs211 Sophia cs211 Emma cs211 Olivia cs211 Eve cs211 Tom cs211 Lily cs210 John cs210 William cs210 Susan cs210 Jack cs210 Jennifer cs210 Sophia cs210 Emma cs210 Olivia cs210 Isabella cs210 Zoe

-------------------------------------------------------------------------------------------

Output lists to screen.

those who took CS210

those who took CS211,

those who took CS210 or CS211,

those who took CS210 and CS211,

those who took CS210 but not CS211,

those who took CS211 but not CS210.

I wrote some code

import java.io.*;

import java.util.*;

class student {

String name;

String course;

}

class Collections_1 {

public static void main(String[] args) throws FileNotFoundException {

ArrayList cs210 = new ArrayList();

ArrayList cs211 = new ArrayList();

ArrayList cs21011 = new ArrayList();

Scanner input = new Scanner(new File("student.txt"));

while (input.hasNext())

{

student s = new student();

s.course = input.next();

s.name = input.next();

cs21011.add(s);

if((s.course).equalsIgnoreCase("cs210"))

{

cs210.add(s);

}

else if (s.course.equalsIgnoreCase("cs211"))

{

cs211.add(s);

}

}

System.out.println("Students took CS210:");

for (int i = 0; i

System.out.println(cs210.get(i).name);

}

System.out.println("Students took CS211:");

for (int i = 0; i

System.out.println(cs211.get(i).name);

}

input.close();

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!