All pastes #1341716 Raw Edit

Miscellany

public java v1 · immutable
#1341716 ·published 2009-02-19 03:33 UTC
rendered paste body
import java.util.Scanner;public class Tester {	public static void main(String args[])	{			ListArrayBased aList = new ListArrayBased();		int choice = 0;		String title, artist, category;		int rating, index = 1;		Scanner in = new Scanner(System.in);				try		{			//Loops until there is no room for input.			while (choice !=7) 			{								//Creates the menu.				System.out.println(" \n"								 + "1. Add CD\n"								 + "2. Remove CD \n"								 + "3. Switch order \n"								 + "4. Find CD \n"								 + "5. Display list \n"								 + "6. Empty list \n"								 + "7. Exit \n");				System.out.println("Selection: ");				//Checks for next available integer input.				choice = in.nextInt();				if(choice == 1) // Add CD				{					try			        {						Scanner inAdd = new Scanner(System.in);												System.out.print("Enter album title:");						title = inAdd.nextLine();						aList.add(index, title);			        						System.out.print("Enter artist name:");						artist = inAdd.nextLine();						aList.add(index, artist);			        						System.out.print("Enter genre:");						category = inAdd.nextLine();						aList.add(index, category);			        						System.out.print("Enter rating:");						rating = inAdd.nextInt();						aList.add(index, rating);						//FileWriter out = new FileWriter("cd.txt");												//PrintWriter out = new PrintWriter(new FileWriter("cd.txt"));						//out.print(title + " " + artist + " " + category + " " + rating);						inAdd.close();			        }										finally					{											}			        			        System.out.println("Album entered into collection. \n");				}								else if(choice == 2) // Remove CD				{					Scanner inRemove = new Scanner(System.in);					System.out.println("Enter the number of the CD you would like removed");					index = inRemove.nextInt();					aList.remove(index);					System.out.println("Album #" + index + " has been removed from the collection. \n");				}								else if(choice == 3) // Switch order				{					Scanner inSwitch = new Scanner(System.in);					System.out.println("Enter the number of the first CD you would like to switch");					int index1 = inSwitch.nextInt();					System.out.println("Enter the number of the second CD you would like to switch");					int index2 = inSwitch.nextInt();					aList.switchPos(index1, index2);					System.out.println("Albums " + index1 + " and " + index2 + " have been switched. \n");				}								else if(choice == 4) // Find CD				{					Scanner inFind = new Scanner(System.in);					System.out.println("Enter the name of the album you would like to find");					String album = inFind.next();					//				}								else if(choice == 5) // Display list				{					aList.display();				}									else if(choice == 6) // Empty list				{					Scanner inEmpty = new Scanner(System.in);					System.out.println("Are you sure you would like to empty the whole collection? (Y/N)");					String yorn = inEmpty.next();										if (yorn.equalsIgnoreCase("y"))					{						aList.removeAll();						System.out.println("The entire collection has been emptied. \n");					}					else if (yorn.equalsIgnoreCase("n"))					{											}					else					{						System.out.println("Invalid answer.");					}				}								else if(choice == 7) // Exit				{					System.out.println("Goodbye.");				}								else 				{					System.out.println("Input error. Please try again.");				}			}		}		catch (ArrayIndexOutOfBoundsException exception)		{			System.out.println("Too many values entered. Array out of bounds.");		}				/*catch(FileNotFoundException e)		{			System.out.println("Error! File Not Found!");			//System.out.print("in: ");			e.printStackTrace();		}*/	}}