/*I am tryin to add or compare a suspect to a list of suspect in the server
what I keep gettin is
SuspectClient.java:67: cannot resolve symbol
symbol : variable sock
location: class SuspectClient
ObjectOutputStream oos = new ObjectOutputStream( sock.getOutputStream() );
^
can anyone help me thank you*/
import java.net.*;
import java.io.*;
import javax.swing.*;
import java.util.ArrayList;
public class SuspectClient {
public static void main(
String[ ] args ) {
if ( args.length < 1 ) {
System.err.println( "DateClient <IP address of server>" );
return;
}
Socket sock = new Socket( "127.0.0.1", 8951 );
ObjectInputStream ois = new ObjectInputStream( sock.getInputStream() );
ObjectOutputStream oos = new ObjectOutputStream(sock.getOutputStream() );
oos.writeObject("Can I have the date?");
// oos.flush();
String choice = (String) ois.readObject();
do {
choice = JOptionPane.showInputDialog("Enter :\n"
+ " add: to Add a suspect to a list\n"
+ " compare: to Compare a suspect to all suspects\n"
+ " Show all: to Show all the suspect in the list\n"
+ "quit to Quit");
if (choice.equalsIgnoreCase("add"))
doAdd();
/*else if (choice.equalsIgnoreCase("compare"))
doCompare();*/
}while( choice.equalsIgnoreCase("quit") == false);
sock.close();
}
public static void doAdd(){
String name = JOptionPane.showInputDialog( "Enter Suspect name: ");
String sheight = JOptionPane.showInputDialog( "Enter Suspect Height: ");
String sage = JOptionPane.showInputDialog( "Enter Suspect Age: ");
String eyeColor = JOptionPane.showInputDialog( "Enter Suspect Eye color: ");
int height = Integer.parseInt(sheight);
int age = Integer.parseInt(sage);
Suspect s =new Suspect(height,age,eyeColor);
s.setName(name);
//ObjectOutputStream oos = new ObjectOutputStream( sock.getOutputStream() );
oos.writeObject(s);
oos.flush();
//oos.reset();
}
/*public static void doCompare(){
String name = JOptionPane.showInputDialog( "Enter Suspect name: ");
String sheight = JOptionPane.showInputDialog( "Enter Suspect Height: ");
String sage = JOptionPane.showInputDialog( "Enter Suspect Age: ");
String eyeColor = JOptionPane.showInputDialog( "Enter Suspect Eye color: ");
int height = Integer.parseInt(sheight);
int age = Integer.parseInt(sage);
Suspect another = new Suspect(height,age,eyeColor);
another.setName(name);
//ObjectOutputStream oos = new ObjectOutputStream( sock.getOutputStream() );
oos.writeObject(another);*/
//}
*/
}
class Suspect implements Serializable
{
private String name;
private int height;
private int age;
private String eyeColor;
//public Setter
public void setName( String name){
this.name = name;
}
public void setHeight( int height){
this.height = height;
}
public void setAge( int age){
this.age = age;
}
public void setEyeColor( String eyeColor){
this.eyeColor = eyeColor;
}
//public getter
public String getName() {
return name;
}
public int getHeight(){
return height;
}
public int getAge(){
return age;
}
public String getEyeColor() {
return eyeColor;
}
public String toString(){
return "Name: " + name + "\t Height: " + height + "\t Age: " + age + "\t Eye Color: " + eyeColor +"\n" ;
}
public boolean validSuspect (Suspect s){
if( (age == s.age) && (height == s.height) && (eyeColor.equalsIgnoreCase(s.eyeColor)) )
return true;
else
return false;
}
//constructor
public Suspect( int h , int a, String e) {
height=h;
age=a;
eyeColor=e;
}
public Suspect( String n) {
name = n;
}
}
