I am new at java.
I am making an address book program.
Below is a code of the Search class.
Could anyone please look into it?
The program is giving a problem while runtime.
import java.io.*;
import java.util.*;
class search
{
private String str,sval;
private String arr[]=new String[8];
char ch1='y',ch2;
private int n,ctr;
clear c1=new clear();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void calc()throws IOException
{
DataInputStream in=new DataInputStream(new FileInputStream("adbk.txt")); //file read
System.out.println("How would you like to search?");
System.out.println("1)by fn");
System.out.println("2)by ln");
System.out.println("3)by area code");
System.out.println("4)by city");
System.out.println("5)by state");
System.out.println("enter choice:");
n=Integer.parseInt(br.readLine())-1;
c1.clr(); //clr here
switch(n)
{
case 1:
{
System.out.println("enter fn");
}
case 2:
{
System.out.println("enter ln");
}
case 3:
{
System.out.println("enter arcd");
}
case 4:
{
System.out.println("enter city");
}
case 5:
{
System.out.println("enter state");
}
default:
{
System.out.println("error");
break;
}
}
sval=br.readLine();
c1.clr(); //clr here
while(in.available()!=0)
{
str=in.readLine();
StringTokenizer st=new StringTokenizer(str," ");
for(int i=0;i<8;i++)
{
arr[i]=st.nextToken();
}
if(sval==arr[n])
{
ctr++;
for(int i=0;i<8;i++)
{
System.out.print(arr[i]+" ");
System.out.println();
}
}
}
System.out.println("Total hits="+ctr);
}
public static void main(String args[])
{
search s=new search();
try
{
s.calc();
}
catch(IOException e)
{
System.out.println("error");
}
}
}
Help will be highly appreciated.:)