how to i convert this case to loop...please help.....

how to i convert this case to loop...please help.....

import java.util.LinkedList; import java.util.*; import java.io.*; import java.lang.*;

public class LinkedListv4 {

char question;
Scanner console = new Scanner(System.in);
LinkedList listA = new LinkedList();

public void Switchers(){

            System.out.println("| a. Append a specified elements to the list");
            System.out.println("| b. Add an element at specified index");
            System.out.println("| c. Add a new elements in front of the list");
            System.out.println("| d. Add new elements with a specified value into the list alternately");
            System.out.println("| e. Remove the first element in the list");
            System.out.println("| f. Find an element at a specified position in the list");
            System.out.println("| g. Replace the elements at a specified index");
            System.out.println("| h. Print the list");
            System.out.println("| i. Print the list from a specified index");
            System.out.println("| j. Print the list in reverse order");
            System.out.println("| k. Remove all elements in the list");
            System.out.println("| l. Check for empty list");
            System.out.println("| q. Quit");



            question = console.next().charAt(0);
            System.out.println();



            switch (question) {
              case 'a': AppendElement();

              case 'b': AddElementSpecific();

              case 'c': AddElementFront();

              case 'd': EditExistingList();

              case 'e': RemoveFirstElement();

              case 'f': ViewElements();

              case 'g': ReplaceElement();

              case 'h': PrintList();

              case 'i': PrintListSpecific();

              case 'j': PrintReverseOrder();

              case 'k': ClearAll();

              case 'l': CheckEmptyList();

              case 'q': Quit(); 

              case 'Q': Quit(); break;

              default: System.out.println("Invalid Input"); 
                        System.out.println();
                        Switchers(); break;
}

}

            //1 --- DONE
            public void AppendElement() {

                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println("| Create/Store objects in an LinkedList container.                    |");
                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println();

                    System.out.println("Please set maximum elements required");
                    System.out.println();
                    int Max = console.nextInt();

                    for (int i = 0; i < Max; i++) {

                        System.out.println("Please insert number for element "+ i);
                        double element = console.nextDouble();
                        System.out.println("  - Storing Number(" + element + ")");
                        listA.add(new Double(element));
                    }

                        System.out.println();
                        System.out.println("+---------------------------------------------------------------------+");
                        System.out.println("| Retrieve objects in an LinkedList container using an Iterator.      |");
                        System.out.println("+---------------------------------------------------------------------+");
                        System.out.println();

                        Iterator Ite = listA.iterator();
                            while (Ite.hasNext()) {
                                System.out.println(Ite.next());
                            }

                            Switchers();

            }

            //2 --- DONE FIXED - ???
            public void AddElementSpecific() {



                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println("| Create/Store objects in specified  LinkedList container.            |");
                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println();

                    System.out.println("Please insert specified index :");
                    int index = console.nextInt();

                        System.out.println("Please insert number for element  :");
                        double element = console.nextDouble();
                        System.out.println("  - Storing Number(" + element + ")");
                        listA.add(index,new Double(element));

                        System.out.println();
                        System.out.println("+---------------------------------------------------------------------+");
                        System.out.println("| Retrieve objects in an LinkedList container using an Iterator.      |");
                        System.out.println("+---------------------------------------------------------------------+");
                        System.out.println();

                        Iterator Ite = listA.iterator();
                            while (Ite.hasNext()) {
                                System.out.println(Ite.next());


                            }

                            Switchers();

                }

            //3 --- DONE
            public void AddElementFront() {

                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println("| Create/Store objects in front of LinkedList container.              |");
                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println();

                        int i= 0;
                        System.out.println("System will store element to the first index, Insert new element please  :");
                        double element = console.nextDouble();
                        System.out.println("  - Storing Number(" + element + ")");
                        listA.add(0,new Double(element));


                        System.out.println();
                        System.out.println("+---------------------------------------------------------------------+");
                        System.out.println("| Retrieve objects in an LinkedList container using an Iterator.      |");
                        System.out.println("+---------------------------------------------------------------------+");
                        System.out.println();

                        Iterator Ite = listA.iterator();
                            while (Ite.hasNext()) {
                                System.out.println(Ite.next());


                            }

                            Switchers();
                }

            //4 --- DONE - ???
            public void EditExistingList() {

                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println("| Add new elements with a specified value into the list alternately   |");
                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println();
                    System.out.println();
                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println("| Retrieve objects in an LinkedList container using an Iterator.      |");
                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println();
                    Iterator IteInitial = listA.iterator();
                            while (IteInitial.hasNext()) {
                                System.out.println(IteInitial.next());
                            }

                    System.out.println("Please choose desirable index to modify elements");
                    System.out.println();
                    int SpecIndex = console.nextInt();
                    listA.remove(SpecIndex);

                        System.out.println("Please insert new number for element "+ SpecIndex);
                        double element = console.nextDouble();
                        System.out.println("  - Storing Number(" + element + ")");
                        listA.add(SpecIndex,new Double(element));

                        System.out.println();
                        System.out.println("+---------------------------------------------------------------------+");
                        System.out.println("| Retrieve objects in an LinkedList container using an Iterator.      |");
                        System.out.println("+---------------------------------------------------------------------+");
                        System.out.println();

                        Iterator Ite = listA.iterator();
                            while (Ite.hasNext()) {
                                System.out.println(Ite.next());
                            }

                            Switchers();                        

                }

            //5 --- DONE
            public void RemoveFirstElement() {

                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println("|      Remove fisrt element in the LinkedList container.              |");
                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println();

                    Object object = listA.removeFirst();
                    System.out.println(object + " has been removed from the first index of LinkedList");

                    System.out.println();
                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println("| Retrieve objects in an LinkedList container using an Iterator.      |");
                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println();

                    Iterator Ite = listA.iterator();
                    while (Ite.hasNext()) {
                    System.out.println(Ite.next());


                            }

                            Switchers();

                }

            //6 --- DONE
            public void ViewElements() {

                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println("| Find an element at a specified position in the list                 |");
                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println();
                    System.out.println();
                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println("| Retrieve objects in an LinkedList container using an Iterator.      |");
                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println();

                    Iterator Ite = listA.iterator();
                    while (Ite.hasNext()) {
                    System.out.println(Ite.next());
                    }

                    System.out.println("Select any element in the list to review index position :");
                    double element = console.nextDouble();
                    System.out.println();

                    int NotNegOne = listA.indexOf(element);

                    if (NotNegOne != -1) {
                      System.out.println("element "+element+" is at index "+listA.indexOf(element));
                    } 

                    else {
                      System.out.println("LinkedList does not contain "+element);
                    }

                    Switchers();

                }


            //7 --- DONE
            public void ReplaceElement() {

                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println("| Replace the elements at a specified index                           |");
                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println();
                    System.out.println();
                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println("| Retrieve objects in an LinkedList container using an Iterator.      |");
                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println();
                    Iterator IteInitial = listA.iterator();
                            while (IteInitial.hasNext()) {
                                System.out.println(IteInitial.next());
                            }

                    System.out.println();
                    System.out.println("Please choose desirable index to modify elements");
                    System.out.println();
                    int SpecIndex = console.nextInt();
                    listA.remove(SpecIndex);

                        System.out.println("Please insert new number for index "+ SpecIndex);
                        double element = console.nextDouble();
                        System.out.println("  - Storing Number(" + element + ")");
                        listA.add(SpecIndex,new Double(element));

                        System.out.println();
                        System.out.println("+---------------------------------------------------------------------+");
                        System.out.println("| Retrieve objects in an LinkedList container using an Iterator.      |");
                        System.out.println("+---------------------------------------------------------------------+");
                        System.out.println();

                        Iterator Ite = listA.iterator();
                            while (Ite.hasNext()) {
                                System.out.println(Ite.next());
                            }

                    Switchers();

                }

            //8 --- DONE
            public void PrintList() {

                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println("|      Print List in the LinkedList container.                    |");
                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println();

                    if (listA.isEmpty()){
                    System.out.println("Linked list is empty");
                    }
                    else{
                     System.out.println (listA);
                    }

                    Switchers();

                }

            //9 --- DONE
            public void PrintListSpecific() {

                                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println("|      Print List from specified index in the LinkedList container.   |");
                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println();

                    try {

                    int indexSize = listA.size();
                    int realIndexSize = indexSize - 1;
                    System.out.println("Total Index in LinkedList (counting from O) "+realIndexSize);
                    System.out.println();
                    System.out.println();
                    System.out.println("Please choose desirable index to view its element");
                    System.out.println();
                    int SpecIndex = console.nextInt();
                    System.out.println();
                    System.out.println("The element is "+listA.get(SpecIndex)+" at index "+SpecIndex);

                    }

                    catch ( Exception e )  {
                        System.out.println();
                        System.out.println("LinkedList does not contain index requested");  
                    }


                    Switchers();

                }

            //10 --- DONE
            public void PrintReverseOrder() {

                    System.out.println();
                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println("| Reverse the list in the LinkedList container.                       |");
                    System.out.println("+---------------------------------------------------------------------+");
                    System.out.println();

                    ListIterator itr = listA.listIterator();

                    System.out.println("Iterating through elements of Java LinkedList using ListIterator in forward direction...");
                    while(itr.hasNext())
                    {
                    System.out.println(itr.next());
                    }

                    System.out.println("Iterating through elements of Java LinkedList using ListIterator in reverse direction...");
                    while(itr.hasPrevious())
                    {
                    System.out.println(itr.previous());
                    }


            Switchers();

                }

            //11 --- DONE
            public void ClearAll() {

                System.out.println("+---------------------------------------------------------------------+");
                System.out.println("|      Clear entire LinkedList                                        |");
                System.out.println("+---------------------------------------------------------------------+");
                System.out.println();

                listA.clear();
                System.out.println("All element has been removed");
                System.out.println();
                System.out.println();

                if (listA.isEmpty()){
                    System.out.println("Linked list is empty");
                    }
                    else{
                     System.out.println (listA);
                    }

                Switchers();

                }

            //12 --- DONE
            public void CheckEmptyList() {

                if (listA.isEmpty()){
                    System.out.println();
                    System.out.println("Linked list is empty");
                    System.out.println();
                    }
                    else{
                     System.out.println (listA);
                    }

                Switchers();

                }

            //13 ---DONE
            public void Quit() {

                System.exit(0);
                }


public static void main (String args[]) {

    LinkedListv4 MYlinkList = new LinkedListv4();
    MYlinkList.Switchers();
}

}

View Answers

September 19, 2011 at 11:14 AM

Do modifications in Switchers() method:

public void Switchers(){
              boolean exit=false;
              do{
            System.out.println("| a. Append a specified elements to the list");
            System.out.println("| b. Add an element at specified index");
            System.out.println("| c. Add a new elements in front of the list");
            System.out.println("| d. Add new elements with a specified value into the list alternately");
            System.out.println("| e. Remove the first element in the list");
            System.out.println("| f. Find an element at a specified position in the list");
            System.out.println("| g. Replace the elements at a specified index");
            System.out.println("| h. Print the list");
            System.out.println("| i. Print the list from a specified index");
            System.out.println("| j. Print the list in reverse order");
            System.out.println("| k. Remove all elements in the list");
            System.out.println("| l. Check for empty list");
            System.out.println("| q. Quit");


            System.out.print("Enter your choice: ");
            question = console.next().charAt(0);
            System.out.println();



            switch (question){
              case 'a': AppendElement();
                        break;

              case 'b': AddElementSpecific();
                        break;

              case 'c': AddElementFront();
                        break;

              case 'd': EditExistingList();
                        break;

              case 'e': RemoveFirstElement();
                        break;

              case 'f': ViewElements();
                        break;

              case 'g': ReplaceElement();
                        break;

              case 'h': PrintList();
                        break;

              case 'i': PrintListSpecific();
                        break;

              case 'j': PrintReverseOrder();
                        break;

              case 'k': ClearAll();
                        break;

              case 'l': CheckEmptyList();
                        break;

              case 'q': Quit();
                        exit=true;
                        break;

              case 'Q': Quit();
                        exit=true;
                        break;

              default: System.out.println("Invalid Input"); 
                        System.out.println();
                         break;

}
              }
              while(!exit);

}









Related Tutorials/Questions & Answers:
how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....   */ import...(); case 'i': PrintListSpecific(); case 'j': PrintReverseOrder...(); case 'q': Quit(); case 'Q': Quit(); break
how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....   */ import...(); case 'i': PrintListSpecific(); case 'j': PrintReverseOrder...(); case 'q': Quit(); case 'Q': Quit(); break
Advertisements
how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....   */ import...(); case 'i': PrintListSpecific(); case 'j': PrintReverseOrder...(); case 'q': Quit(); case 'Q': Quit(); break
how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....   */ import...(); case 'i': PrintListSpecific(); case 'j': PrintReverseOrder...(); case 'q': Quit(); case 'Q': Quit(); break
how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...(); case 'i': PrintListSpecific(); case 'j': PrintReverseOrder...(); case 'q': Quit(); case 'Q': Quit(); break
how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...(); case 'i': PrintListSpecific(); case 'j': PrintReverseOrder...(); case 'q': Quit(); case 'Q': Quit(); break
how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...(); case 'i': PrintListSpecific(); case 'j': PrintReverseOrder...(); case 'q': Quit(); case 'Q': Quit(); break
how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...(); case 'i': PrintListSpecific(); case 'j': PrintReverseOrder...(); case 'q': Quit(); case 'Q': Quit(); break
how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...(); case 'i': PrintListSpecific(); case 'j': PrintReverseOrder...(); case 'q': Quit(); case 'Q': Quit(); break
how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...(); case 'i': PrintListSpecific(); case 'j': PrintReverseOrder...(); case 'q': Quit(); case 'Q': Quit(); break
how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...(); case 'i': PrintListSpecific(); case 'j': PrintReverseOrder...(); case 'q': Quit(); case 'Q': Quit(); break
how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...(); case 'i': PrintListSpecific(); case 'j': PrintReverseOrder...(); case 'q': Quit(); case 'Q': Quit(); break
how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...(); case 'i': PrintListSpecific(); case 'j': PrintReverseOrder...(); case 'q': Quit(); case 'Q': Quit(); break
how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...(); case 'i': PrintListSpecific(); case 'j': PrintReverseOrder...(); case 'q': Quit(); case 'Q': Quit(); break
Please tell me how can i convert string to timer
Please tell me how can i convert string to timer  Please tell me how can i convert string to timer
How do I convert a dictionary to a JSON object in Python?
How do I convert a dictionary to a JSON object in Python?  Hi, I... in the JSON document.ADS_TO_REPLACE_1 I want to the easy way to convert... is returning the dictionary object. Now our requirement is to convert it to JSON
hello there i need help
transaction? thats the problem. I dont know how to start this program because i am a beginner, and aside from that i am really eager to learn java please help me with the codes and please explain to me how it works. i only need to use
i need a help in this please
i need a help in this please  The factorial of a nonnegative integer n is written n! (pronounced â?? n factorialâ??) and is defined as follows: n!=n...=input.nextInt(); long num=m; for(int i=m;i>1;i
How can I Convert my Image Files to Text Files? - IDE Questions
How can I Convert my Image Files to Text Files?  How can I Convert my Image Files to Text Files
I have need to help
I have need to help  Write a program that, for four points A, B, C and P, draws a triangle formed by ABC and a small cross showing the position of P; and displays a line of text indicating which of the following three cases
how do i update my database with the help of update syntax in html <text/javascript>? How to write 'where' statement in this?
how do i update my database with the help of update syntax in html ? How... ActiveXObject("ADODB.Recordset"); alert('How are you!!'); cn.Open(strConn); alert('I am Fine!'); rs.Open(sqlmek, cn); alert('Fine
Java : String Case Conversion
Java : String Case Conversion In this section we will discuss how to convert... : By using toLowerCase() method you can convert any upper case char/String... : By using toUpperCase() method you can convert any lower case char/String into upper
how to highlight the field in image,when i have entered into that corresponding field's textbox-any one help out
how to highlight the field in image,when i have entered into that corresponding field's textbox-any one help out  how to highlight the field in image,when i have entered into that corresponding field's textbox. Here webpage
Java String Case Converter
Java String Case Converter Here we are going to convert lowercase characters.... If there is a lowercase character then convert it into uppercase using Character.toUpperCase(ch[i... then convert it into lowercase using Character.toLowerCase(ch[i]) and append
i need help - Development process
in the background. please guide me how i can run my program in the background...i need help  hello, i need help regarding this program. public...()); } } } it is printing the result of ping in to a file,but if i want
i need help - Development process
i need help  hello, i need help regarding this program. this program... IPAddress on command line, but i want to take it dynamically and it must store the result of ping in to a file . can anyone guide me how to do it please
i need help plz .... Quickly
i need help plz .... Quickly   how can i count how many numbers enterd by the user so the output would be like this Total number of Scores = .... this is my code :- (adsbygoogle = window.adsbygoogle || []).push
i need help to solve this problem
i need help to solve this problem  Write a stack class ArrayStack.java implements PureStack interface that reads in strings from standard input.... H and I join the queue h. G leaves the queue i. H and I leave the queue
how to convert jsp to exe
how to convert jsp to exe  hello sir, i am doing... to another system. so i want to convert this to exe. that will executed only internet... tomcat5.0,j2se5.0 and jsp,servlets i am using.this is doing in localhost only. now i want
i need to replace this if statement code with switch case code
i need to replace this if statement code with switch case code   i need to replace this code with switch case for(int i=0;i<100;i++){ if((i...){ switch(i/j){ case 3: System.out.println ("java
actually i want to knw how to include an google page inside a tab(suppose in 2nd tab).can any one help me....
how to include an google page inside a tab(suppose in 2nd tab).can any one help me....  actually i want to knw how to include an google page inside a tab(suppose in 2nd tab).can any one help me
I need help in doing this. - Java Beginners
I need help in doing this.  Student DataBase i will need creating... objects that will house the birthdates for each student member. (I have...() { switch (month) { case 4: case 6: case 9: case 11: if (day <= 30
pls i need help with my assignment
pls i need help with my assignment  how to write a code that ask the user for the height of the triangle and prints the triangle using * eg if height is 3 it prints * and also using import java.util.Scanner
how can create pop() method in this program ,Or how can delete image in it when i press pop button in runtime ??? please help me ...
how can create pop() method in this program ,Or how can delete image in it when i press pop button in runtime ??? please help me ...   ...[aray.length]; Integer[] intArray = new Integer[aray.length]; for (int i = 0; i
How to convert Mssql Procedure into Mysql Procedure.
How to convert Mssql Procedure into Mysql Procedure.  Hello Sir, I have a mssql procedure and i need it to be converted to mysql... AND @StartRow - 1 Plz sir help me to convert it into mysql
How to convert Mssql Procedure into Mysql Procedure.
How to convert Mssql Procedure into Mysql Procedure.  Hello Sir, I have a mssql procedure and i need it to be converted to mysql... AND @StartRow - 1 Plz sir help me to convert it into mysql
Mysql Lower Case
Mysql Lower Case       Mysql Lower Case is used to convert the Upper Case letter to the Lower Case... an example from 'Mysql Lower Case. To understand this example we create a table
how to convert ACSII to HEX
how to convert ACSII to HEX  How to convert perticular ASCII... value of ~:00   The given code accepts the string and convert...() to convert it to Hex value. class ConvertAsciiToHex { public static void
PLZ HELP ME. i need php code.
PLZ HELP ME. i need php code.   I want php code for bellow OUTPUT. output is just example but it must be letters only. abc bcd efg jku rgt azs hje qqc wws adt
Begineer Help Help Please Thanks A million ) I am using Jcreator
Begineer Help Help Please Thanks A million ) I am using Jcreator  System.out.println(" Income Statement...: $ 1.00 Retained Earnings: $ 2.00 I don't know how to sort the array
Mysql Lower Case
Mysql Lower Case       Mysql Lower Case is used to convert the Upper Case letter to the Lower Case. Understand With Example ADS_TO_REPLACE_1 The section
How to Convert String to Date?
How to Convert String to Date?  Hi, I am new in Java and learning the Date manipulation in Java. I have to write a program in Java which converts... have to convert it to Date object. Tell me How to Convert String to Date? Thanks
How to convert a String to an int?
How to convert a String to an int?  I my program I am taking... format. Now I want to convert into int value. Tell me How to convert a String... contains the value 1025, then you can use the following code to convert the String
How to convert NSString to NSInteger?
How to convert NSString to NSInteger?  Hi, Provide me code to convert NSString into NSInteger. Thanks   Hi, Use the following code example: NSString * s= @"100"; NSInteger i = [s intValue]; Thanks
How to write the new Criteria Query in my case?
How to write the new Criteria Query in my case?  Hi expert, I am using hibernate 5.2.1. However, I do not know how to change the following deprecated code into the new Criteria Query. My old code is : try{ tx
i need some help in understanding the following codes.thanks..
i need some help in understanding the following codes.thanks..  this code is to perform LocalColorHistogram.But i can't understand it public... * height; int i = 0; int j = 0; int k = 0; double
How to Convert ArrayList to Array?
How to Convert ArrayList to Array?  Hi, I am trying to learn to Convert ArrayList to Array. How it is possible? How to Convert ArrayList to Array? Thanks   Hi, To Convert ArrayList to array ArrayList.toArray
help i want it now the answer pleas...
help i want it now the answer pleas...  write a program that will display the exactly output as below: Hints: declare and initialize value of array in double type.Read and write all elements of array.perform the multiply
How to convert String into java.util.Date
How to convert String into java.util.Date  Hi, How I can convert String date into java.util.Date in a Java program? Thanks   Hi... Getting time in Milliseconds Convert Date To Calendar How to convert String Date
How to create own help forum - JSP-Servlet
How to create own help forum  Hi All, My client given requirements, they need to create their own help forum, I need to do case study for, how to create any forum. if you have any documentation or technical ideas please

Ads