Question

Could you help me pleas , this is my code I want change it to insert...

Could you help me pleas , this is my code I want change it to insert student by user , and i have problem when i want append name it just one time i can't append or present more one.

>>>>>>>>>>>>>>>>>>>.


import java.util.Iterator;
import java.util.Scanner;


public class studentDLLTest {

static int getChoice() {
Scanner in = new Scanner(System.in);
int choice;
do {
System.out.print("\nYour choice? : ");
choice = in.nextInt();
} while (choice < 1 || choice > 9);
return choice;
}

public static void PrompetText() {
System.out.println("Insert Method code to test it :\ncode\t\tmethod:\n*************************************");
System.out.println("(1):\t\tAppend");
System.out.println("(2):\t\tprepend");
System.out.println("(3):\t\tExtractFirst");
System.out.println("(4):\t\tExtractLast");
System.out.println("(5):\t\tExtract Student");
System.out.println("(6):\t\tinsert after");
System.out.println("(7):\t\tinsert before");
System.out.println("(8):\t\tQuite");
}

public static void SLLOperations(StudentLinkedList myGroup) {
Scanner in = new Scanner(System.in);
int choise;
do {
choise = getChoice();
switch (choise) {
case 1: {
System.out.println("Enter Student Name followed by Reg. Number:");
String name = in.nextLine();
int id = in.nextInt();
Student s = new Student(name, id);
myGroup.append(s);
}
break;
case 2: {
System.out.println("Enter Student Name followed by Reg. Number:");
String name = in.nextLine();
int id = in.nextInt();
Student s = new Student(name, id);
myGroup.prepend(s);
}
break;
case 3: {
myGroup.extractFirst();
}
break;
case 4: {
myGroup.extractLast();
}
break;
case 5: {
System.out.print("Enter Student Name you want to delete:");
String name = in.nextLine();
myGroup.extract(name);
}
break;
case 6: {
System.out.print("Enter New Student Name followed by Reg. Number::");
String name = in.nextLine();
int id = in.nextInt();
Student s = new Student(name, id);
System.out.println("Enter the Current Name of Student to insert after it :");
Scanner x = new Scanner(System.in);
String sname = x.nextLine();
StudentLinkedList.Node temp = myGroup.searchByName(sname);
temp.insertAfter(s);
}
break;
case 7: {
System.out.print("Enter New Student Name followed by Reg. Number::");
String name = in.nextLine();
int id = in.nextInt();
Student s = new Student(name, id);
System.out.println("Enter the Current Name of Student to insert Before it :");
Scanner x = new Scanner(System.in);
String sname = x.nextLine();
StudentLinkedList.Node temp = myGroup.searchByName(sname);
temp.insertBefore(s);
}


}
break;

}
} while (choise != 8);
}

public static void DLLOperations(StudentDLinkedList myGroup) {
Scanner in = new Scanner(System.in);
int choise;
do {
choise = getChoice();
switch (choise) {
case 1: {
System.out.println("Enter Student Name followed by Reg. Number:");
String name = in.nextLine();
int id = in.nextInt();
Student s = new Student(name, id);
myGroup.append(s);
}
break;
case 2: {
System.out.println("Enter Student Name followed by Reg. Number:");
String name = in.nextLine();
int id = in.nextInt();
Student s = new Student(name, id);
myGroup.prepend(s);
}
break;
case 3: {
myGroup.extractFirst();
}
break;
case 4: {
myGroup.extractLast();
}
break;
case 5: {
System.out.print("Enter Student Name you want to delete:");
String name = in.nextLine();
myGroup.extract(name);
}
break;
case 6: {
System.out.print("Enter New Student Name followed by Reg. Number:");
String name = in.nextLine();
int id = in.nextInt();
Student s = new Student(name, id);
System.out.println("Enter the Current Name of Student to insert after it :");
Scanner x = new Scanner(System.in);
String sname = x.nextLine();
StudentDLinkedList.Node temp = myGroup.searchByName(sname);
temp.insertAfter(s);
}
break;
case 7: {
System.out.print("Enter New Student Name followed by Reg. Number:");
String name = in.nextLine();
int id = in.nextInt();
Student s = new Student(name, id);
System.out.println("Enter the Current Name of Student to insert Before it :");
Scanner x = new Scanner(System.in);
String sname = x.nextLine();
StudentDLinkedList.Node temp = myGroup.searchByName(sname);
temp.insertBefore(s);
}
break;

}
  

}
} while (choise != 8);
}
  

public static void main(String[] args) {
Student[] s = new Student[3];
s[0] = new Student("A ", 1);
s[1] = new Student("EB",00344 );
s[2] = new Student("BAS IRI", 100334);
  
Scanner in = new Scanner(System.in);
System.out.println("please Enter Linked List Type:\n(1)SingluLinkedList\n(2)DoublyLinkedList ");
int choise = in.nextInt();
switch (choise) {
case 1: {
StudentLinkedList myGroup = new StudentLinkedList();
for (int i = 0; i < s.length; i++) {
myGroup.insert(s[i]);
}
PrompetText();

SLLOperations(myGroup);

}
break;
case 2: {
StudentDLinkedList myGroup = new StudentDLinkedList();
for (int i = 0; i < s.length; i++) {
myGroup.insert(s[i]);
}
PrompetText();
DLLOperations(myGroup);
}
break;
}

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the modified code below.

CODE

import java.util.Iterator;

import java.util.Scanner;

public class studentDLLTest {

static int getChoice() {

Scanner in = new Scanner(System.in);

int choice;

do {

System.out.print("\nYour choice? : ");

choice = in.nextInt();

} while (choice < 1 || choice > 9);

return choice;

}

public static void PrompetText() {

System.out.println("Insert Method code to test it :\ncode\t\tmethod:\n*************************************");

System.out.println("(1):\t\tAppend");

System.out.println("(2):\t\tprepend");

System.out.println("(3):\t\tExtractFirst");

System.out.println("(4):\t\tExtractLast");

System.out.println("(5):\t\tExtract Student");

System.out.println("(6):\t\tinsert after");

System.out.println("(7):\t\tinsert before");

System.out.println("(8):\t\tQuite");

}

public static void SLLOperations(StudentLinkedList myGroup) {

Scanner in = new Scanner(System.in);

int choise;

do {

choise = getChoice();

switch (choise) {

case 1: {

System.out.println("Enter Student Name followed by Reg. Number:");

String name = in.nextLine();

int id = in.nextInt();

in.nextLine();

Student s = new Student(name, id);

myGroup.append(s);

}

break;

case 2: {

System.out.println("Enter Student Name followed by Reg. Number:");

String name = in.nextLine();

int id = in.nextInt();

in.nextLine();

Student s = new Student(name, id);

myGroup.prepend(s);

}

break;

case 3: {

myGroup.extractFirst();

}

break;

case 4: {

myGroup.extractLast();

}

break;

case 5: {

System.out.print("Enter Student Name you want to delete:");

String name = in.nextLine();

myGroup.extract(name);

}

break;

case 6: {

System.out.print("Enter New Student Name followed by Reg. Number::");

String name = in.nextLine();

int id = in.nextInt();

in.nextLine();

Student s = new Student(name, id);

System.out.println("Enter the Current Name of Student to insert after it :");

Scanner x = new Scanner(System.in);

String sname = x.nextLine();

StudentLinkedList.Node temp = myGroup.searchByName(sname);

temp.insertAfter(s);

}

break;

case 7: {

System.out.print("Enter New Student Name followed by Reg. Number::");

String name = in.nextLine();

int id = in.nextInt();

in.nextLine();

Student s = new Student(name, id);

System.out.println("Enter the Current Name of Student to insert Before it :");

Scanner x = new Scanner(System.in);

String sname = x.nextLine();

StudentLinkedList.Node temp = myGroup.searchByName(sname);

temp.insertBefore(s);

}

}

break;

}

} while (choise != 8);

}

public static void DLLOperations(StudentDLinkedList myGroup) {

Scanner in = new Scanner(System.in);

int choise;

do {

choise = getChoice();

switch (choise) {

case 1: {

System.out.println("Enter Student Name followed by Reg. Number:");

String name = in.nextLine();

int id = in.nextInt();

Student s = new Student(name, id);

myGroup.append(s);

}

break;

case 2: {

System.out.println("Enter Student Name followed by Reg. Number:");

String name = in.nextLine();

int id = in.nextInt();

Student s = new Student(name, id);

myGroup.prepend(s);

}

break;

case 3: {

myGroup.extractFirst();

}

break;

case 4: {

myGroup.extractLast();

}

break;

case 5: {

System.out.print("Enter Student Name you want to delete:");

String name = in.nextLine();

myGroup.extract(name);

}

break;

case 6: {

System.out.print("Enter New Student Name followed by Reg. Number:");

String name = in.nextLine();

int id = in.nextInt();

Student s = new Student(name, id);

System.out.println("Enter the Current Name of Student to insert after it :");

Scanner x = new Scanner(System.in);

String sname = x.nextLine();

StudentDLinkedList.Node temp = myGroup.searchByName(sname);

temp.insertAfter(s);

}

break;

case 7: {

System.out.print("Enter New Student Name followed by Reg. Number:");

String name = in.nextLine();

int id = in.nextInt();

Student s = new Student(name, id);

System.out.println("Enter the Current Name of Student to insert Before it :");

Scanner x = new Scanner(System.in);

String sname = x.nextLine();

StudentDLinkedList.Node temp = myGroup.searchByName(sname);

temp.insertBefore(s);

}

break;

}

}

} while (choise != 8);

}

public static void main(String[] args) {

Student[] s = new Student[3];

s[0] = new Student("A ", 1);

s[1] = new Student("EB",00344 );

s[2] = new Student("BAS IRI", 100334);

Scanner in = new Scanner(System.in);

System.out.println("please Enter Linked List Type:\n(1)SingluLinkedList\n(2)DoublyLinkedList ");

int choise = in.nextInt();

switch (choise) {

case 1: {

StudentLinkedList myGroup = new StudentLinkedList();

for (int i = 0; i < s.length; i++) {

myGroup.insert(s[i]);

}

PrompetText();

SLLOperations(myGroup);

}

break;

case 2: {

StudentDLinkedList myGroup = new StudentDLinkedList();

for (int i = 0; i < s.length; i++) {

myGroup.insert(s[i]);

}

PrompetText();

DLLOperations(myGroup);

}

break;

}

}

}

NOTE: If you still get the same error, please help to provide me the code for other classes like Student.java, StudentDLinkedList.java, StudentDLinkedList.Node, StudentLinkedList.java so that I can replicate the issue in my local environment and debug the issue.

Add a comment
Know the answer?
Add Answer to:
Could you help me pleas , this is my code I want change it to insert...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need to add a method high school student, I couldn't connect high school student to...

    I need to add a method high school student, I couldn't connect high school student to student please help!!! package chapter.pkg9; import java.util.ArrayList; import java.util.Scanner; public class Main { public static Student student; public static ArrayList<Student> students; public static HighSchoolStudent highStudent; public static void main(String[] args) { int choice; Scanner scanner = new Scanner(System.in); students = new ArrayList<>(); while (true) { displayMenu(); choice = scanner.nextInt(); switch (choice) { case 1: addCollegeStudent(); break; case 2: addHighSchoolStudent(); case 3: deleteStudent(); break; case...

  • java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and sh...

    java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and short by name, course, instructor, and location. ///main public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<Student>students = new ArrayList<>(); int choice; while(true) { displayMenu(); choice = in.nextInt(); switch(choice) { case 1: in.nextLine(); System.out.println("Enter Student Name"); String name...

  • Please make the following code modular. Therefore contained in a package with several classes and not...

    Please make the following code modular. Therefore contained in a package with several classes and not just one. import java.util.*; public class Q {    public static LinkedList<String> dogs = new LinkedList<String> ();    public static LinkedList<String> cats = new LinkedList<String> ();    public static LinkedList<String> animals = new LinkedList<String> ();    public static void enqueueCats(){        System.out.println("Enter name");        Scanner sc=new Scanner(System.in);        String name = sc.next();        cats.addLast(name);        animals.addLast(name);    }   ...

  • For this code after case 0, I need it to ask the user if they would...

    For this code after case 0, I need it to ask the user if they would like to see the menu again and some type of if statement or loop to ask them yes or no and if yes print again and if no end program. So it would ask if they would like to see the menu again then ask what their choice is. If yes print menu and if no end program. import java.util.InputMismatchException; import java.util.*; import java.io.*;...

  • I am working on this switch statement code and I am getting errors. Please help. import...

    I am working on this switch statement code and I am getting errors. Please help. import java.util.Scanner; public class Switchstatement { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here } class Convertor { public static void main(String[] args) {    int choice;    Double Yen, UsDollars, Kilometer, Miles, Kilograms, Pounds, Inches; Double Centimeters, result;       Scanner scanner = new Scanner(System.in);    System.out.print("Enter 1\t UsDollars to Yen:...

  • Here is everything I have on my codes, the compiler does not allow me to input...

    Here is everything I have on my codes, the compiler does not allow me to input my name, it will print out "Please enter your name: " but totally ignores it and does not allow me to input my name and just proceeds to my result of ID and Sale. Please help. I've bolded the part where it I should be able to input my name package salesperson; public class Salesperson { String Names; int ID; double Sales; // craeting...

  • In this same program I need to create a new method called “int findItem(String[] shoppingList, String...

    In this same program I need to create a new method called “int findItem(String[] shoppingList, String item)” that takes an array of strings that is a shopping list and a string for an item name and searches through the “shoppingList” array for find if the “item” exists. If it does exist print a confirmation and return the item index. If the item does not exist in the array print a failure message and return -1. import java.util.Scanner; public class ShoppingList...

  • Need help with the UML for this code? Thank you. import java.util.Scanner;    public class Assignment1Duong1895...

    Need help with the UML for this code? Thank you. import java.util.Scanner;    public class Assignment1Duong1895    {        public static void header()        {            System.out.println("\tWelcome to St. Joseph's College");        }        public static void main(String[] args) {            Scanner input = new Scanner(System.in);            int d;            header();            System.out.println("Enter number of items to process");            d = input.nextInt();      ...

  • Please answer both questions thank you. Assuming that a user enters 8, 15, and 11 as...

    Please answer both questions thank you. Assuming that a user enters 8, 15, and 11 as input values one after another, separated by spaces, what is the output of the following code snippet? int num1 = 0; int num2 = 0; int num3 = 0; Scanner in = new Scanner (System.in); System.out.print("Enter a number: "); numl - in.nextInt(); System.out.print("Enter a number: "); num2 = in.nextInt(); System.out.print("Enter a number: "); num3 = in.nextInt(); if (numl > num2) if (numl > num3)...

  • Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In...

    Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In my Shopping Cart Manager Class (Bottom Code), I get "Resource leak: 'sc' is never closed." I have tried multiple things and cannot figure it out. Thank you. Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In my Shopping Cart Manager Class (Bottom Code), I get "Resource leak: 'sc' is never closed." I have tried multiple things and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT