Can I simplify my phone look-up program? I needed to make a phone number look-up program with 10 contacts. I feel like I can shorten the program up a bit, it seems very long, but I don't know how. Any suggestion? Do I need all of the Java imports?

package phoneLookUp;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;


public class phoneLookUp
{
static HashMap&lt;String,String&gt; contact = new HashMap&lt;String, String&gt;();

// Method getName() will return the name for given number if it is exist in the contact

public static String getName(String number)
{
Set set = contact.entrySet();
Iterator it = set.iterator();

while(it.hasNext())
{
Map.Entry me = (Map.Entry)it.next();

String tNum = (String)me.getValue();

if(tNum.equals(number))
{
return (String)me.getKey();
}

}

//if given number is not found

return "";
}

// Method getNumber() will return the Name of the given phone number if it is exist in the contact


public static String getNumber(String name)
{
Set set = contact.entrySet();
Iterator it = set.iterator();

while(it.hasNext())
{
Map.Entry me = (Map.Entry)it.next();

String tName = (String)me.getKey();

if(tName.equals(name))
{
String formattedNumber = outputFormat((String)me.getValue());
return formattedNumber;
}

}

// if name if not found in the contact

return "";
}

// Formatting the given phone number


public static String outputFormat(String phone)
{
String temp = "(";

for(int i = 0; i &lt; phone.length(); i++)
{
if(i &lt; 2)
temp += phone.charAt(i);

else if(i == 2)
temp += phone.charAt(i)+") ";

else if(i &lt; 5)
temp += phone.charAt(i);

else if(i == 5)
temp += phone.charAt(i)+" - ";

else
temp += phone.charAt(i);
}

return temp;

}

public static void main(String args[])
{
Scanner sc = new Scanner(System.in);

// contacts

contact.put("Tom","6037571122");
contact.put("Alice","6037779057");
contact.put("George","6037779103");
contact.put("Ben", "6031234322");
contact.put("Jack","6037764522");
contact.put("Greg","6039985434");
contact.put("Franklin","60344578993");
contact.put("Sam", "6033458765");
contact.put("Mike","6036673322");
contact.put("Alex", "6035561199");




System.out.println("Welcome to the Phone Look up Program ");


char ch = ' ';

do
{
System.out.print("please enter the name or phone number ( no delemeters please) (q to quit) : ");
String input = sc.next();

ch = input.charAt(0);

if(ch == 'q')
break;

// Finding whether given input is Name or Phone Number

if(Character.isDigit(ch))
{
String name = getName(input);

if(!name.equals(""))
System.out.println("Number : "+outputFormat(input)+" belongs to : "+name);

else
System.out.println("There is no listing for : "+outputFormat(input));
}

else
{
String phone = getNumber(input);

if(!phone.equals(""))
System.out.println(input+"'s"+" phone number is : "+phone);

else
System.out.println("There is no listing for : "+input);
}


}while(true);

}

}


This is my output:


  Welcome to the Phone Look up Program
  please enter the name or phone number ( no delemeters please) (q to quit) : Alice
  Alice's phone number is : (603) 777 - 9057
  please enter the name or phone number ( no delemeters please) (q to quit) : Tom
  Tom's phone number is : (603) 757 - 1122
  please enter the name or phone number ( no delemeters please) (q to quit) : Sally
  There is no listing for : Sally
  please enter the name or phone number ( no delemeters please) (q to quit) : q
Yes , you don't need to iterate through the map to know if it contains a certain value or not, you can just call get

 String contact = contacts.get(name);
 if(contact == null){
  // no such value
 }


You might have notice that I called it contacts instead of contact, because a map is a collection that holds things and things are plural.
Note: If you need to iterate over a map, don't use iterator, use enhanced-for instead.

for(Map.Entry&lt;String,String&gt; entry: map.entrySet()){

}


any language you use, you have to follow its naming conventions. Use Pascal casing for classes in Java

    class PhoneLookUp


and not 

    class phoneLookUp


Use StringBuilder instead of String when you need to append frequently. Every time you do += on a String, it creates a new String because strings are immutable in Java, consider using StringBuilder instead.

  public static String outputFormat(String phone)
  {
  StringBuilder temp = new StringBuilder("(");

   for(int i = 0; i &lt; phone.length(); i++)
   {
   if(i &lt; 2){
     temp.append(phone.charAt(i));
   }
   else if(i == 2){
    temp.append(phone.charAt(i)+") ");
   }
   .....
  return temp.toString();

  }