I'm making an address book program and I'm to add/delete/find people.
This is my contact class
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;
}
}
and this is my main class
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());
}
}
So heres my thing, is it possible for me to use a scanner for everything that I do? For example. When I want to add someone in I have a method for that but, its resolved to a single variable a1, how would I automatically have that be resolved to a2 for the next instance?
Furthermore how would I go about deleting someone from the book using the scanner? I can do it all in the code but obviously thats not ideal for an address book?