class and I am having trouble
getting my delete a contact case to work.
/**
* David Martinez
* Project 0
* IT/CS 111
*/
import java.util.Scanner;
import java.io.*;
import java.util.InputMismatchException;
enum data_type{ID, SSN}
class LinkedListNode
{
private int num=0;
private LinkedListNode next;
Contact info = new Contact();
public LinkedListNode()
{
setNode(null);
}
public LinkedListNode(Contact data, LinkedListNode myNode)
{
setItem(data);
setNode(myNode);
}
public void setItem(Contact data)
{
info = data;
}
public void setNode(LinkedListNode myNode)
{
next = myNode;
}
public Contact getItem()
{
return info;
}
public LinkedListNode getNode()
{
return next;
}
public String toString()
{
return " " + info;
}
}
class LinkedList{
private String list;
LinkedListNode head;
public LinkedList(LinkedListNode obj)
{
list = " ";
head = obj;
}
public String toString()
{
list = "";
LinkedListNode tempNode = head.getNode();
System.out.println();
while(tempNode != null)
{
list = list + " " + tempNode;
tempNode = tempNode.getNode();
}
return list;
}
}
//Making the classes needed for program
class Contact
{
public String first;
public String last;
public String toString () {
return first + " " + last + " " + phone + " " + data + " " + address;
}
Phone phone = new Phone();
Data data = new Data();
Address address = new Address();
}
class Phone
{
int area_code=0;
int prefix=0;
int suffix=0;
public String toString(){
return " " + area_code+ " " + prefix + " " + suffix;
}
}
class Address{
int housenumber=0;
public String street;
public String city;
public String state;
int zipcode=0;
public String toString(){
return housenumber + " " + street + " " + city + " " + state + " " + zipcode;
}
}
class Data
{
char idorssn;
data_type x;
public int value = 0;
public String toString(){
if (x == data_type.ID){
return "900" + value;
}else{
return "" + value;
}
}
}
public class project0 {
private static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args) {
String temp;
LinkedList start;
LinkedListNode tN, tN1, pos, head;
LinkedListNode newNode = null;
head = new LinkedListNode();
start = new LinkedList(head);
pos = head;
char idorssn=0,findContact=0;
int user_choice = 0;
String first, last, street, city, state, zipcode;
keyboard.useDelimiter("\\n");
System.out.println("David Martinez");
System.out.println("Project 0");
System.out.println("20081107");
while (user_choice != 5){
System.out.println("1)Create new contacts:");
System.out.println("2)Delete Contacts:");
System.out.println("3)Show Contacts:");
System.out.println("4)Find Contacts:");
System.out.println("5)End Program");
try
{
user_choice = keyboard.nextInt();
}
catch (InputMismatchException e)
{
keyboard.next();
}
finally {}
switch (user_choice){
case 1:
newNode = new LinkedListNode();
System.out.println("Enter First Name:");
newNode.info.first = keyboard.next();
System.out.println("Enter Last Name:");
newNode.info.last = keyboard.next();
keyboard.useDelimiter("\\s");
System.out.print("Enter the Phone Number of this student: (###)-###-####:");
newNode.info.phone.area_code = keyboard.nextInt();
newNode.info.phone.prefix = keyboard.nextInt();
newNode.info.phone.suffix = keyboard.nextInt();
keyboard.useDelimiter("\\n");
System.out.println("Enter House/Apartment number:");
newNode.info.address.housenumber = keyboard.nextInt();
System.out.println("Enter Street name:");
newNode.info.address.street = keyboard.next();
System.out.println(" Enter city:");
newNode.info.address.city = keyboard.next();
System.out.println("Enter state:");
newNode.info.address.state = keyboard.next();
System.out.println("Enter zip code:");
newNode.info.address.zipcode = keyboard.nextInt();
System.out.println("I)Enter the ID for the contact:");
System.out.println("S)Enter this contacts social security number: ###-##-####:");
newNode.info.data.idorssn = keyboard.next().charAt(0);
idorssn = newNode.info.data.idorssn;
switch (idorssn){
case 'i':
case 'I':
System.out.println("ID number: 900");
newNode.info.data.x=data_type.ID;
break;
case 's':
case 'S':
System.out.println("SNN:");
newNode.info.data.x=data_type.SSN;
break;
default:
System.out.println("User error please try again");
}
newNode.info.data.value = keyboard.nextInt();
pos.setNode(newNode);
pos = newNode;
break;
case 2:
System.out.println("Select a contact to be deleted:");
tN = head;
temp = keyboard.next();
tN1 = head.getNode();
while(tN1 != null){
if (tN1.getItem() == temp){
tN.setNode(tN1.getNode());
tN1 = tN.getNode();
}else{
tN = tN.getNode();
tN1 = tN1.getNode();
}
}
pos = tN;
break;
case 3:
System.out.println(start);
break;
case 4:
System.out.println("F) Find contact with first name:");
System.out.println("L) Find contact with last name:");
System.out.println("I) Find contact with ID number:");
System.out.println("S) Find contact with SSN:");
System.out.println("P) Find contact with Phone number:");
switch (findContact){
case 'f':
case 'F':
break;
case 'l':
case 'L':
break;
case 'i':
case 'I':
break;
case 's':
case 'S':
break;
case 'p':
case 'P':
break;
}
break
case 5:
System.out.println("Goodbye");
break;
}
}
}
}

New Topic/Question
Reply




MultiQuote




|