// CSE 143, Autumn 2015 // This program demonstrates the use of stacks and queues. // It reads in a file of students' exam scores in reverse order, such as: // // Zahn William 92 // Yu Vivian 95 // Wolf Adam 87 // // And first strips the ones who got 100 on the exam using a queue, // then prints the rest in reverse order using a stack. // WARNING: this version of this program is incomplete. It has some bugs // and style issues. Do not use it as an example of good code. import java.util.*; import java.io.*; public class Exams { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("ta.txt")); Queue tas = new LinkedList(); Stack backup = new Stack(); // read the lines from the file (in reverse ABC order) into a queue while(input.hasNextLine()) { tas.add(input.nextLine()); } // filter out the students who got 100 on the exam for(int i = 0; i < tas.size(); i++) { String ta = tas.remove(); if(!ta.endsWith("100")) { tas.add(ta); } } System.out.println(tas); // TODO: print all of the students' information in ABC order } }