In this version, you are to reimplement the functionality of version 1, but this time using the classes you coded in Lab 3. The basic output is identical to that of version 1, but now: The three parallel arrays are gone — replaced with a single array of type PhonebookEntry. You should be reading in the entries using the read method of your PhonebookEntry class (which in turn uses the read methods of the Name and PhoneNumber classes). Use the equals methods of the Name and PhoneNumber classes in your lookup and reverseLookup methods. Use the toString methods to print out information. Make 100 the capacity of your Phonebook array Throw an exception (of class Exception) if the capacity of the Phonebook array is exceeded. Place a try/catch around your entire main and catch both FileNotFoundExceptions and Exceptions (remember, the order of appearance of the exception types in the catch blocks can make a difference). Do not use BufferedReader while(true) breaks The name of your application class should be Phonebook. Also, you should submit ALL your classes (i.e., Name, Strip off public from all your class definintions Sample Run #1 For example, if the file phonebook.text contains: Arnow David (123)456-7890 Harrow Keith (234)567-8901 Jones Jackie (345)678-9012 Augenstein Moshe (456)789-0123 Sokol Dina (567)890-1234 Tenenbaum Aaron (678)901-2345 Weiss Gerald (789)012-3456 Cox Jim (890)123-4567 Langsam Yedidyah (901)234-5678 Thurm Joseph (012)345-6789 Here is a sample execution of the program. User input is in bold. Your program should replicate the prompts and output: lookup, reverse-lookup, quit (l/r/q)? l last name? Arnow first name? David David Arnow's phone number is (123)456-7890 lookup, reverse-lookup, quit (l/r/q)? r phone number (nnn-nnn-nnnn)? (456)789-0123 (456)789-0123 belongs to Moshe Augenstein lookup, reverse-lookup, quit (l/r/q)? l last name? Weiss first name? Jerrold -- Name not found lookup, reverse-lookup, quit (l/r/q)? l last name? Weiss first name? Gerald Gerald Weiss's phone number is (789)012-3456 lookup, reverse-lookup, quit (l/r/q)? r phone number (nnn-nnn-nnnn)? (111)123-4567 -- Phone number not found lookup, reverse-lookup, quit (l/r/q)? q 3 lookups performed 2 reverse lookups performed Sample Run #2 If the file phonebook.text contains: … … more than 100 names … … … Here is a sample execution of the program. User input is in bold. Your program should replicate the prompts and output: *** Exception *** Phonebook capacity exceeded - increase size of underlying array Sample Run #3 If the file phonebook.text is missing: Here is a sample execution of the program. User input is in bold. Your program should replicate the prompts and output: *** IOException *** phonebook.text (No such file or directory) name class: import java.io.*; import java.util.*; public class Name { public Name(String last, String first) {        this.last = last;        this.first = first; } public Name(String first) {        this("", first); } public boolean equals(Name same) {    return first.equals(same.first) && last .equals(same.last);    } public String toString() {    return first + " " + last; } public String getFormal() {    return first + " " + last; } public String getOfficial() {    return last + ", " + first; }    public static Name read(Scanner scan) {    if (!scan.hasNext())        return null;        String first = scan.next();        String last = scan.next();        return new Name(first, last); } public String getInitials() {    return Character.toUpperCase(first.charAt(0)) + "." + Character.toUpperCase(last.charAt(0))+"."; } private String last, first; public static void main(String [] args) throws Exception { Scanner scan = new Scanner(new File("names.text")); int count = 0; Name readName = read(scan); Name readLastName =null; while(readName != null) {    if(readLastName!=null && readName!=null && readLastName.equals(readName)){        System.out.println("Duplicate name \""+readName+"\" discovered");    }    else{            System.out.println("name: " + readName);            System.out.println("formal: " + readName.getFormal());            System.out.println("official: " + readName.getOfficial());            System.out.println("initials: " + readName.getInitials());            System.out.println();        }        count++;    readLastName= readName;    readName = read(scan); }        System.out.println("---");    System.out.println(count + " names processed."); } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In this version, you are to reimplement the functionality of version 1, but this time using the classes you coded in Lab 3. The basic output is identical to that of version 1, but now:

The three parallel arrays are gone — replaced with a single array of type PhonebookEntry.

You should be reading in the entries using the read method of your PhonebookEntry class (which in turn uses the read methods of the Name and PhoneNumber classes).

Use the equals methods of the Name and PhoneNumber classes in your lookup and reverseLookup methods.

Use the toString methods to print out information.

Make 100 the capacity of your Phonebook array

Throw an exception (of class Exception) if the capacity of the Phonebook array is exceeded.

Place a try/catch around your entire main and catch both FileNotFoundExceptions and Exceptions (remember, the order of appearance of the exception types in the catch blocks can make a difference).

Do not use

BufferedReader while(true)

breaks

The name of your application class should be Phonebook. Also, you should submit ALL your classes (i.e., Name, Strip off public from all your class definintions

Sample Run #1

For example, if the file phonebook.text contains:

Arnow David (123)456-7890 Harrow Keith (234)567-8901 Jones Jackie (345)678-9012 Augenstein Moshe (456)789-0123 Sokol Dina (567)890-1234 Tenenbaum Aaron (678)901-2345 Weiss Gerald (789)012-3456 Cox Jim (890)123-4567 Langsam Yedidyah (901)234-5678 Thurm Joseph (012)345-6789

Here is a sample execution of the program.
User input is in bold. Your program should replicate the prompts and output:

lookup, reverse-lookup, quit (l/r/q)? l
last name? Arnow
first name? David
David Arnow's phone number is (123)456-7890

lookup, reverse-lookup, quit (l/r/q)? r
phone number (nnn-nnn-nnnn)? (456)789-0123
(456)789-0123 belongs to Moshe Augenstein

lookup, reverse-lookup, quit (l/r/q)? l
last name? Weiss
first name? Jerrold
-- Name not found

lookup, reverse-lookup, quit (l/r/q)? l
last name? Weiss
first name? Gerald
Gerald Weiss's phone number is (789)012-3456

lookup, reverse-lookup, quit (l/r/q)? r
phone number (nnn-nnn-nnnn)? (111)123-4567
-- Phone number not found

lookup, reverse-lookup, quit (l/r/q)? q

3 lookups performed
2 reverse lookups performed

Sample Run #2

If the file phonebook.text contains:

… … more than 100 names … … …

Here is a sample execution of the program.
User input is in bold. Your program should replicate the prompts and output:

*** Exception *** Phonebook capacity exceeded - increase size of underlying array

Sample Run #3

If the file phonebook.text is missing:

Here is a sample execution of the program.
User input is in bold. Your program should replicate the prompts and output:

*** IOException *** phonebook.text (No such file or directory)

name class:

import java.io.*;
import java.util.*;
public class Name {
public Name(String last, String first) {
       this.last = last;
       this.first = first;
}
public Name(String first) {
       this("", first);
}
public boolean equals(Name same) {
   return first.equals(same.first) && last .equals(same.last);
  
}
public String toString() {
   return first + " " + last;
}

public String getFormal() {
   return first + " " + last;
}
public String getOfficial() {
   return last + ", " + first;
}
  
public static Name read(Scanner scan) {
   if (!scan.hasNext())
       return null;
       String first = scan.next();
       String last = scan.next();
       return new Name(first, last);
}
public String getInitials() {
   return Character.toUpperCase(first.charAt(0)) + "." + Character.toUpperCase(last.charAt(0))+".";
}
private String last, first;
public static void main(String [] args) throws Exception {
Scanner scan = new Scanner(new File("names.text"));
int count = 0;
Name readName = read(scan);
Name readLastName =null;
while(readName != null) {
   if(readLastName!=null && readName!=null && readLastName.equals(readName)){
       System.out.println("Duplicate name \""+readName+"\" discovered");
   }
   else{
           System.out.println("name: " + readName);
           System.out.println("formal: " + readName.getFormal());
           System.out.println("official: " + readName.getOfficial());
           System.out.println("initials: " + readName.getInitials());
           System.out.println();
       }
       count++;
   readLastName= readName;
   readName = read(scan);
}
       System.out.println("---");
   System.out.println(count + " names processed.");
}
}

 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 2 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education