tohobaby 0 Newbie Poster

If i want to put tis sentece "No Such Data." where did i nit to implement it into if there was no data found?

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

class Book {

 	static Map<String, String> phone = new HashMap<String, String>();
 	public static void main(String args [])throws Exception{

  searchBook();

  int option;

  do{
   phoneMenu();
   option = getOption();
   processOption(option);
  }while(true);

 }

   	 private static void phoneMenu(){
	 System.out.println("1--> Add new telephone number: ");
	 System.out.println("2--> Search number by name: ");
	 System.out.println("3--> Exit ");
   	 System.out.println("------------------");

	 }

	private static int getOption(){
 	int option;

 	Scanner sc = new Scanner (System.in);
 	System.out.print("Please select an option: ");
 	option = sc.nextInt();
 	return option;
	}

	private static void processOption(int o)throws Exception{

 	switch(o){

  	case 1:
  		System.out.println("You select one");
   		addNumber();
   	break;

   	case 2:
   		System.out.println("You select two");
   		searchNumber();
   	break;

    case 3:
     System.out.println("Bye Bye");
     saveNumber();
     System.exit(0);

     default:
      System.out.println("Invalid option!");
 	}

 	System.out.println("Press any key to continue");
 	System.in.read();
 }


	private static void searchBook(){

 	ObjectInputStream in = null;
 	HashMap hMap = new HashMap();

 		try{
  			in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("phone.dat")));
  			hMap = (HashMap) in.readObject();
  			Set hSet = hMap.entrySet();
  			Iterator iterator = hSet.iterator();
  			while(iterator.hasNext()){
   			Map.Entry me = (Map.Entry) iterator.next();
   			hMap.put(me.getKey(), me.getValue());
   		
  		}

	 }catch(Exception e){
 }

 finally{

  try{
   	phone.putAll(hMap);
   	in.close();
   }

   catch (IOException ex){
   }
  }
 }

		private static void addNumber(){

		String name = " ";
 		String number = " ";
 		Scanner sc = new Scanner(System.in);//scann in
 		System.out.println("Enter Friend: ");
 		name = sc.next();
 		System.out.println("Enter Telephone No: ");
 		number = sc.next();
 		phone.put(name, number);
		}

		private static void searchNumber(){
 		Scanner sc = new Scanner(System.in);//scann wat
 		System.out.println("Enter Friend: ");
 		String name = sc.next();
 		String display = " ";
 		Set hSet = phone.entrySet();
 		Iterator hMinator = hSet.iterator();

 	while(hMinator.hasNext()){
 	Map.Entry hTry = (Map.Entry)hMinator.next();
  	if(hTry.getKey().toString().equalsIgnoreCase(name))
   	display = hTry.getKey().toString()+
    "\n"+hTry.getValue().toString();
 	}
 System.out.println(display);
}

	private static void saveNumber()throws Exception{

 	ObjectOutputStream out = null;

 	out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream("phone.dat")));

 	out.writeObject(phone);

 	out.close();

	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.