Mein Programm ist über Telefonverzeichnis Ich wurde verwendet verknüpfte Liste Ich habe ein Problem in diesem Code hat es keine Syntaxfehler, aber ich kann die Antwort nicht sehen, wenn ich suche und listet auch ich hoffe Sie Update-MethodeTelefonbuch mit verknüpfter Liste
hinzufügen Dies ist erste Klasse:
//-----------------------------------------------------------------------------------------
class tel
{
private static String name;
private static String address;
private static int phoneNo;
private tel next;
private tel prev;
public tel(){
}
public tel(String name1,String address1 ,int phoneNo1)
{
name = name1 ;
address = address1;
phoneNo = phoneNo1;
}
public static String getName() {
return name;
}
public void setName(String name1) {
name = name1;
}
public static String getAddress() {
return address;
}
public void setAddress(String address1) {
address = address1;
}
public static int getPhoneNo() {
return phoneNo;
}
public void setPhoneNo(int phoneNo1) {
phoneNo = phoneNo1;
}
public tel getNext() {
return next;
}
public void setNext(tel next1) {
next = next1;
}
public tel getPrev() {
return prev;
}
public void setPrev(tel prev1) {
prev = prev1;
}
public void display()
{
System.out.println("Name : " + getName() + " PhoneNo : " + getPhoneNo() + " Address : " + getAddress());
}
}
//-------------------------------------------------------------------------------------------------------------------
//2ed class
public class telList {
private tel first;
private tel last;
private tel cur ;
public telList()
{
first = null ;
last = null ;
}
public boolean isEmpty()
{return first == null; }
public tel getCur() {
return cur;
}
public void setCur(tel cur1) {
cur = cur1;
}
public void insert(String na,String addr ,int pho)
{
tel newtel = new tel(na,addr,pho);
if (isEmpty())
{
last = newtel;
first = newtel;
}
else
{
newtel.setNext(first);
first.setPrev(newtel);
first = newtel;
}
}
//////////////////////////////////
public tel search(String Key)
{
tel cur = first;
while(cur.getName() != Key)
{
if(cur.getNext()== null)
return null;
else
cur = cur.getNext();
}
return cur;
}
public void displaythelist()
{
tel cur = first;
while(cur != null)
{
System.out.println(cur.display());
cur = cur.getNext();
}
System.out.println(" ");
}
}
//3ed class
//-------------------------------------------------------------------------------------------------------------------
import java.io.*;
import java.util.*;
public class telTest {
public static void main(String[] args)throws Exception {
Scanner input = new Scanner(System.in);
boolean quit = false;
do {
int menu = 0;
System.out.println("******************************");
System.out.println("Telephone Directory");
System.out.println();
System.out.println("1. Accept Data");
System.out.println("2. Search");
System.out.println("3. List of all persons");
System.out.println("4. Exit");
System.out.print("Please enter your choice: ");
menu = input.nextInt();
System.out.println();
tel t = new tel();
telList t1 = new telList();
switch (menu) {
case 1:
System.out.print("Enter Name: ");
String name = input.next();
t.setName(name);
System.out.print("Enter Address: ");
String address = input.next();
t.setAddress(address);
System.out.print("Enter Phone No: ");
int no = input.nextInt();
t.setPhoneNo(no);
t1. insert(t.getName(),t.getAddress(),t.getPhoneNo());
break ;
//...........................................................................
case 2:
System.out.print("Enter name to search information: ");
String n = input.next();
try {
t1.search(t.getName());
}
catch (Exception e) {
}
break;
//...........................................................................
case 3://list
try {
t1.displaythelist();
}
catch (Exception e) {
}
break;
//...........................................................................
case 4 ://exit
quit = true;
break;
//...........................................................................
default:
System.out.println("Invalid Entry!");
}
}while (!quit);
}
}
Gibt es hier eine Frage? –
@Darin Im Kommentar rechts oben: "Mein Programm ist über Telefonverzeichnis Ich wurde verwendet verknüpfte Liste Ich habe ein Problem in diesem Code hat keine Syntaxfehler, aber ich kann die Antwort nicht sehen, wenn ich auch suche und auflisten Ich hoffe, dass Sie Update-Methode hinzufügen " – marcog
@marcog, ich fragte mehr über * Frage * in Bezug darauf, wie sie auf StackOverflow gefragt werden sollten: Erklären Sie das Szenario, präsentieren Sie die erwarteten und tatsächlichen Ergebnisse und wie sie sich unterscheiden, das Problem eingrenzen zu einem kleinen Code-Schnipsel, der gepostet werden sollte, weitere nützliche Informationen geben, ... –