Question: combine these three programs in one main 1 First program import java.util.Scanner; class Nodel public String data; public Node address: public Node(String d, Node a)




combine these three programs in one main 1 First program import java.util.Scanner; class Nodel public String data; public Node address: public Node(String d, Node a) data =d; address = a; > > class Llist private Node firstNode; public LList0{firstNode=null;) public void add (String new entry) Node newNode = new Node(newEntry,firstNode): firstNode=newNode; > public String remove(int p) String resulte null; iff(p>=1)&&(pcgetLength()) { if(p==1) result=firstNode.data; firstNode=firstNode address: ) else Node nodeBefore=firstNode; Node nodeToRemove=null; Node nodeAfter=null; for(int i=1;i > else System.out.println("Sorry position is invalid"); return result: > public void print() Node temp = firstNode;/like array i=0 while(temp!=null) // like end of the array System.out.println(temp.data)://like array items [1] temp=temp.address://i++ like array > 1 public void add (String newEntry, int p) if((p>=1)&&(p System.out.println(lastNode.data); lastNode.address=newNode; else // in between { Node newNode = new Node(newEntry, null); Node nodeBefore = firstNode; for(int i=1;i public int getLength() Int result=0; Node temp = firstNode; Ilike array i=0 while(temp!=null) // like end of the array { result++://like array items[ temp=temp.address://i++ like array 3 return result; } public void clear firstNode=null; } public boolean isEmpty return (firstNode==null); > J ublic class Linked_Listimplementation { / * @param args the command line arguments public static void main(String[] args) { // TODO code application logic here Scanner scan = new Scanner(System.in); LList myList = new Llist(); intc; do a System.out.println("1- add a new item to the list"); System.out.println("2-add a new item at a position in the list); System.out.println("3- remove an item at a position in the list"); System.out.println("4- Clear all the list"); System.out.println("5- how many items in the list"); System.out.println("6- To replace an item in the list"); System.out.println("7- to print the item at a position"); System.out.println("8- to search if an item exist or not"); System.out.println("9- to check whether the list is empty or not"); System.out.println("99- Print the list"); System.out.println("100-Exit"); System.out.printin("Plz enter your choice"); c = scan.nextInt(); if (c==9) System.out.println("The list is empty "+myList.isEmpty(); /" if(c==8) System.out.println("Piz enter the item to search for"); String newitem = scan.next(); System.out.printin("The item"+newltem+" is found "umyList.contains(newltern}); } if (c==7) 5 { System.out.println("Piz enter the position for the item to print"); int newPos = scan.nextInt(); System.out.printin("The item at position +newPos+" is *umytist.getEntry(newPos)); > if(c==6) System.out.printin("Plz enter the new item"); String newitem = scan.next(); System.out.println("Plz enter the position to replace"); int newPos = scan.nextInt(): System.out.println("The old item replaced is * umyList.replace(newPos, newltem)); } */ if(c==5) { System.out.println("The no of items in the list is -myList.getLength(); > if(c==4) myList.clear(); if(3) System.out.println("Plz enter the position of the item to remove"); int newpos = scan.nextInt(); System.out.println("The removed item is *=myList.remove(newPos); 3 if (c==1) System.out.println("Piz enter the item to add"); String newitem = scan.next(): myList.add(newitem); > if (c=2) { System.out.println("Plz enter the item to add"); String newitem = scan.next(); System.out.println("Piz enter the position"); int newPos = scan.nextInt(): combine these three programs in one main 1 First program import java.util.Scanner; class Nodel public String data; public Node address: public Node(String d, Node a) data =d; address = a; > > class Llist private Node firstNode; public LList0{firstNode=null;) public void add (String new entry) Node newNode = new Node(newEntry,firstNode): firstNode=newNode; > public String remove(int p) String resulte null; iff(p>=1)&&(pcgetLength()) { if(p==1) result=firstNode.data; firstNode=firstNode address: ) else Node nodeBefore=firstNode; Node nodeToRemove=null; Node nodeAfter=null; for(int i=1;i > else System.out.println("Sorry position is invalid"); return result: > public void print() Node temp = firstNode;/like array i=0 while(temp!=null) // like end of the array System.out.println(temp.data)://like array items [1] temp=temp.address://i++ like array > 1 public void add (String newEntry, int p) if((p>=1)&&(p System.out.println(lastNode.data); lastNode.address=newNode; else // in between { Node newNode = new Node(newEntry, null); Node nodeBefore = firstNode; for(int i=1;i public int getLength() Int result=0; Node temp = firstNode; Ilike array i=0 while(temp!=null) // like end of the array { result++://like array items[ temp=temp.address://i++ like array 3 return result; } public void clear firstNode=null; } public boolean isEmpty return (firstNode==null); > J ublic class Linked_Listimplementation { / * @param args the command line arguments public static void main(String[] args) { // TODO code application logic here Scanner scan = new Scanner(System.in); LList myList = new Llist(); intc; do a System.out.println("1- add a new item to the list"); System.out.println("2-add a new item at a position in the list); System.out.println("3- remove an item at a position in the list"); System.out.println("4- Clear all the list"); System.out.println("5- how many items in the list"); System.out.println("6- To replace an item in the list"); System.out.println("7- to print the item at a position"); System.out.println("8- to search if an item exist or not"); System.out.println("9- to check whether the list is empty or not"); System.out.println("99- Print the list"); System.out.println("100-Exit"); System.out.printin("Plz enter your choice"); c = scan.nextInt(); if (c==9) System.out.println("The list is empty "+myList.isEmpty(); /" if(c==8) System.out.println("Piz enter the item to search for"); String newitem = scan.next(); System.out.printin("The item"+newltem+" is found "umyList.contains(newltern}); } if (c==7) 5 { System.out.println("Piz enter the position for the item to print"); int newPos = scan.nextInt(); System.out.printin("The item at position +newPos+" is *umytist.getEntry(newPos)); > if(c==6) System.out.printin("Plz enter the new item"); String newitem = scan.next(); System.out.println("Plz enter the position to replace"); int newPos = scan.nextInt(): System.out.println("The old item replaced is * umyList.replace(newPos, newltem)); } */ if(c==5) { System.out.println("The no of items in the list is -myList.getLength(); > if(c==4) myList.clear(); if(3) System.out.println("Plz enter the position of the item to remove"); int newpos = scan.nextInt(); System.out.println("The removed item is *=myList.remove(newPos); 3 if (c==1) System.out.println("Piz enter the item to add"); String newitem = scan.next(): myList.add(newitem); > if (c=2) { System.out.println("Plz enter the item to add"); String newitem = scan.next(); System.out.println("Piz enter the position"); int newPos = scan.nextInt()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
