주소록 프로그램을 만들고 있는데 사람들을 추가/삭제/찾으려고합니다.이 기능을 위해 스캐너를 구현하는 방법은 무엇입니까?
이 내 연락처 클래스
import java.util.Scanner;
public class Contacts {
String name;
String lastn;
String phone;
public Contacts() {
Scanner sc = new Scanner (System.in);
System.out.println ("Enter the first name >");
String n = sc.next();
System.out.println ("Enter the last name >");
String l = sc.next();
System.out.println ("Enter the phone number (use the format xxx-xxx-xxxx) >");
String p = sc.next();
name = n + " " + l; phone = p;
}
public String getName() { return name; }
public String getPhone() {return phone;}
public String toString() {
String result = name + "\n" + phone;
return result;
}
}
이며,이, 내 일이 그래서를 heres 내 메인 클래스
import java.util.Scanner;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.ObjectInput;
import java.io.PrintWriter;
public class Main {
static final String filePath = System.getProperty("user.dir") + "\\src\\files";
static final String fileName = "ContactInfo.dat";
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
BST<String,Contacts> tree1 = new BST <String,Contacts>();
Contacts a1 = new Contacts();
System.out.println (tree1);
tree1.insert(a1.getName(), a1);
System.out.println (tree1);
System.out.println(a1.getName());
}
}
입니다 제가하는 모든 일의 스캐너를 사용하는 것이 가능하다? 예를 들어. 누군가를 추가하고 싶습니다. 그러나 그 방법을 하나의 변수 a1로 해결했는데, 자동으로 다음 인스턴스에 대해 a2로 해결할 수 있습니까?
기타 스캐너를 사용하여 책에서 누군가를 삭제하는 방법은 무엇입니까? 나는 코드에서 모든 것을 할 수 있지만 분명히 주소록에 이상적이지는 않습니까?