//******************************************************************* // CS 201 Lab 14 // // testMagazineList.java // // Driver to test new methods added to MagazineList.java //******************************************************************* import java.util.Scanner; public class testMagazineList { //---------------------------------------------------------------- // Creates a MagazineList object, adds several magazines to the // list, then prints it. //---------------------------------------------------------------- public static void main (String[] args) { Scanner scan = new Scanner(System.in); MagazineList magazines = new MagazineList(); Magazine mag; String name = ""; int choice = 0, count; System.out.println("\n\nCS-201 Lab 14 Linked Lists\n\n"); while (choice != 6) { choice = inputUserChoice(scan); switch (choice) { case 1: scan.nextLine(); // clear previous input line System.out.print("\n\nEnter a magazine to add to the Front of the list: "); name = scan.nextLine(); magazines.addFront(new Magazine(name)); break; case 2: scan.nextLine(); // clear previous input line System.out.print("\n\nEnter a magazine to add to the BACK the list: "); name = scan.nextLine(); magazines.addBack(new Magazine(name)); break; case 3: mag = magazines.removeFront(); if (mag == null) System.out.println("\n\nThe list is empty."); else System.out.println("\n\nMazazine " + mag + " removed from the FRONT of the list."); break; case 4: count = magazines.count(); System.out.println("\n\nThe are " + count + " magazines in the list."); break; case 5: System.out.println(magazines); case 6: break; default: System.out.println( "\n\nInvalid Choice. Please Re-Enter\n\n"); } } } public static int inputUserChoice(Scanner scan) { System.out.println("\n\n\t1. Add a magazine to the front of the list"); System.out.println("\t2. Add a magazine to the back of the list"); System.out.println("\t3. Remove a magazine from the front of the list"); System.out.println("\t4. Count the number of magazines in the list"); System.out.println("\t5. Display the list of magazines"); System.out.println("\t6. Stop Program"); System.out.print("\n\t Enter your choice: "); return scan.nextInt(); } }