It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Java Forum

a problem about euqal()

a problem about euqal()

Postby maximus710 on Tue Jan 23, 2007 8:07 pm

this is a program to let me open a file and read birthday and related name, and then type name we can fetch the birthday, everything is ok ,whenever i input a name, it always find nothing, can some experts help me please
there are three class i defined, one is birth_reader, another is date to record the date have been read from specified file, one is the name stored firstname and last name, the file my lecture give me is just a simple txt file which is example like:

1 31 1984 robin ralu
.........................

please

import java.util.Scanner.*;
import java.util.*;
import java.io.*;


public class birth_reader
{
public static void main(String[] args)throws IOException
{

birth_reader haha=new birth_reader();
Map <name,date> book=new HashMap<name,date>();

Scanner input=new Scanner(System.in);
name b;
FileReader fin = new FileReader("birthday.txt");
Scanner sc = new Scanner(fin);








while(sc.hasNext())
{

int cat=sc.nextInt();
int cta=sc.nextInt();
int atc=sc.nextInt();

String first_name=sc.next();
String last_name=sc.next();


date a=new date(cat,cta,atc);

b=new name(first_name,last_name);

book.put(b,a);
System.out.println(book);



}



System.out.println("please enter the name");

String f=input.next();
String l=input.next();

b.firstname=f;
b.lastname=l;


date p=book.get(b);


if((p!=null))
{

System.out.println(b+":"+p);
}

else{ System.out.println("no person here"+" "+b);
}

}
}


public class name
{
String firstname,lastname;
public name(String firstname,String lastname)
{
this.firstname=firstname;
this.lastname=lastname;
}




public String toString()
{
return firstname+" "+lastname;

}

}



public class date
{
int year,month,day;



public date(int year,int month,int day)
{
this.year=year;
this.month=month;
this.day=day;
}

public String toString()
{
return year+" "+month+" "+day;

}

public int getyear()
{
return year;

}

public int getmonth()
{
return month;

}
public int getday()
{
return day;

}

}
maximus710
 
Posts: 0
Joined: Tue Jan 23, 2007 7:58 pm

Who is online

Users browsing this forum: No registered users and 0 guests