Course Hero Logo

Assignment10.java - / Assignment #: / Name: / StudentID: /...

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 1 - 3 out of 4 pages.

// Assignment #: Arizona State University CSE205 #10//Name: Your name//StudentID: Your id//Lecture: Your lecture//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 onecharacter{switch (input1){case 'O':// List Current SizeSystem.out.print("The current size is " + list1.size() + "\n");break;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.insertElement(addIndex, str1);System.out.print(str1 + " is inserted at index " + addIndex +"\n");break;case 'I'://Search for the Index of a StringSystem.out.print("Please enter a string to search:\n");inputInfo = stdin.readLine().trim();operation2=list1.searchElement(inputInfo);if (operation2 > -1)
System.out.print(inputInfo + " found at index " + operation2+ "\n");elseSystem.out.print(inputInfo + " not found\n");break;case 'E'://Search for String at an IndexSystem.out.print("Please enter an index to search:\n");inputInfo = stdin.readLine().trim();int searchIndex = Integer.parseInt(inputInfo);System.out.print("string at index " + searchIndex + " is " +list1.getElement(searchIndex) + "\n");break;case 'S'://Set a new element at specified indexSystem.out.print("Please enter a new string to set:\n");String str2 = stdin.readLine().trim();System.out.print("Please enter an index to set:\n");inputInfo = stdin.readLine().trim();int setIndex = Integer.parseInt(inputInfo);list1.setElement(setIndex, str2);System.out.print(str2 + " is set at index " + setIndex + "\n");break;case 'R'://Remove an element at a specified indexSystem.out.print("Please enter an index to remove:\n");inputInfo = stdin.readLine().trim();int removeIndex = Integer.parseInt(inputInfo);list1.removeElement(removeIndex);System.out.print("string at index " + removeIndex + " isremoved\n");break;case 'C'://Count the number of occurences of a specificelementSystem.out.print("Please enter a string to count:\n");inputInfo = stdin.readLine().trim();int counter1 =list1.countHowMany(inputInfo);System.out.print("There are " + counter1 + " " + inputInfo + "found inside the linked list\n");break;case 'D'://Remove all occurences of a given elementSystem.out.print("Please enter a string to remove:\n");inputInfo = stdin.readLine().trim();list1.removeDuplicate(inputInfo);System.out.print(inputInfo + " is removed from the linkedlist\n");break;case 'P'://Append a given element a number of times at theend of the linked listSystem.out.print("Please enter a string to append at theend:\n");String str3 = stdin.readLine().trim();System.out.print("Please enter the number of times you want toappend:\n");inputInfo = stdin.readLine().trim();int times = Integer.parseInt(inputInfo);list1.appendAtEnd(str3, times);System.out.print(str3 + " is appended " + times + " times atend of the linked list\n");break;

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 4 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
N/A
Tags
Object Oriented Programming, System out print

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture