123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
-
- /**
- * Write a description of class PhoneBook1 here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- import java.util.TreeMap;
- import java.util.*;
- import java.util.Scanner;
- public class PhoneBook1
- {
- // instance variables - replace the example below with your own
- private String name, number;
-
- private Map<String, String> entries ;
-
-
- /**
- * Constructor for objects of class PhoneBook1
- */
- public PhoneBook1(){
- this.entries = new TreeMap<String, String>();
- }
-
- /**
- * An example of a method - replace this comment with your own
- *
- * @param y a sample parameter for a method
- * @return the sum of x and y
- */
- public void addNumber(String name, String number){
- this.entries.put(name, number);
-
- }
-
- public void remove(String name){
- if (this.entries.containsKey(name))
- System.out.println("found it");
- this.entries.remove(name);
- }
-
- public void display(){
- if (this.entries.isEmpty()) System.out.println("Empty");
- for (Map.Entry<String, String> entry : entries.entrySet()) {
- String value = entry.getValue();
- String key = entry.getKey();
- System.out.println(key + " " + value);
- }
-
-
-
-
- }
- }
-
|