Assignment10 - Assignment Name StudentID Lab Lecture Description import java.io 10 Daniel Sauter 1202351076 2:00 2:00pm The Assignment 10 class displays

Assignment10 - Assignment Name StudentID Lab Lecture...

This preview shows page 1 - 3 out of 3 pages.

// Assignment #: 10// Name: Daniel Sauter// StudentID: 1202351076// Lab Lecture: 2:00 - 2:00pm// Description: The Assignment 10 class displays a menu of choices to a user// and performs the chosen task. It will keep asking a user to// enter the next choice until the choice of 'Q' (Quit) is// entered.import java.io.*;public class Assignment10{public static void main(String[] args){char input1;String inputInfo = new String();int operation2;String line = new String();//create a linked list to be used in this method.LinkedList list1 = new LinkedList();try{// print out the menuprintMenu();// create a BufferedReader object to read input from a keyboardInputStreamReader isr = new InputStreamReader (System.in);BufferedReader stdin = new BufferedReader (isr);do{System.out.print("What action would you like to perform?\n");line = stdin.readLine().trim(); //read a lineinput1 = line.charAt(0);input1 = Character.toUpperCase(input1);if (line.length() == 1) //check if a user entered only one character{switch (input1){case 'A': //Add StringSystem.out.print("Please enter a string to add:\n");String str1 = stdin.readLine().trim();System.out.print("Please enter an index to add:\n");inputInfo = stdin.readLine().trim();int addIndex = Integer.parseInt(inputInfo);list1.addElement(addIndex, str1);break;case 'D': //Duplicate each elementlist1.duplicateEach();System.out.print("Each element has been duplicated.\n");break;case 'E': //Search for a String at an IndexSystem.out.print("Please enter an index to search:\n");inputInfo = stdin.readLine().trim();int searchIndex = Integer.parseInt(inputInfo);

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture