please code phonebookApp. other classes have been provided. Please follow direction shown in the pictures.      phonenumber class import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class PhoneNumber { private String num; public PhoneNumber(String num) { this.num = num; } public String getAreaCode() { return num.substring(1, 4); } public String getExchange() { return num.substring(5, 8); } public String getLineNumber() { return num.substring(9); } public boolean isFreeToll() { if (getAreaCode().charAt(0) == '8') { return true; } return false; } public String toString() { return "phone number: " + num + "\narea code: " + getAreaCode() + "\nexchange: " + getExchange() + "\nline number: " + getLineNumber(); } public boolean equals(PhoneNumber phoneNum) { if (phoneNum.getAreaCode().compareTo(this.getAreaCode()) == 0 && phoneNum.getExchange().compareTo(this.getExchange()) == 0 && phoneNum.getLineNumber().compareTo(this.getLineNumber()) == 0) { return true; } return false; } public static String read(Scanner scan) { if (scan.hasNextLine()) { return scan.nextLine(); } return null; } public static void main(String[] args) throws FileNotFoundException { Scanner scan = new Scanner(new File("numbers.text")); PhoneNumber phoneNumNext, phoneNum = null; int counts = 0; String val = PhoneNumber.read(scan); while (val != null) { if (phoneNum == null) { phoneNum = new PhoneNumber(val); System.out.println(phoneNum + "\nis toll free: " + phoneNum.isFreeToll() + "\n"); counts++; } else { phoneNumNext = new PhoneNumber(val); if (phoneNum.equals(phoneNumNext)) { System.out.println("Duplicate phone number \"(" + phoneNumNext.getAreaCode() + ")" + phoneNumNext.getExchange() + "-" + phoneNumNext.getLineNumber() + "\" discovered"); } else { System.out.println(phoneNumNext + "\nis toll free: " + phoneNumNext.isFreeToll() + "\n"); } counts++; phoneNum = phoneNumNext; } val = PhoneNumber.read(scan); } System.out.println("---"); System.out.println(counts + " phone numbers processed."); } }       phonebookentry class     import java.util.*; import java.io.*; class PhonebookEntry { private PhoneNumber phoneNumber; private Name name; public PhonebookEntry(Name name,PhoneNumber number) { this.phoneNumber= number; this.name=name; } public String toString() { return name+": "+phoneNumber; } public boolean equals(PhonebookEntry otherEntry) { if(name.equals(otherEntry.name) && !(phoneNumber.equals(otherEntry.phoneNumber)) ) { System.out.println("Warning duplicate name encountered \""+ name+": "+phoneNumber+"\" discovered"); return true; } else if(phoneNumber.equals(otherEntry.phoneNumber) && name.equals(otherEntry.name)) { System.out.println("Duplicate phone book entry \""+otherEntry+"\" discovered"); return false; } return true; } public static PhonebookEntry read(Scanner scanner) { if (!scanner.hasNext()) return null; Name newName = Name.read(scanner); PhoneNumber newphoneNumber = PhoneNumber.read(scanner); return new PhonebookEntry(newName, newphoneNumber); } public void call() { System.out.println("phone book entry: "+name+": "+phoneNumber); if(phoneNumber.isTollFree()) { System.out.println("Dialing (toll-free) "+name+": "+phoneNumber); System.out.println(); } else { System.out.println("Dialing "+name+": "+phoneNumber); System.out.println(""); } } public static void main(String[] args) throws Exception { String tempFirst="temp", tempLast="temp", tempNumber="temp"; PhoneNumber oldNumber= new PhoneNumber(tempNumber); Name oldName= new Name(tempLast,tempFirst); PhonebookEntry temp= new PhonebookEntry(oldName, oldNumber); int count=0; Scanner scanner = new Scanner(new File("phonebook.text")); PhonebookEntry entry=read(scanner); while(entry!=null) { if(entry.equals(temp)) { entry.call(); count++; } else { count++; } oldName=entry.name; oldNumber=entry.phoneNumber; temp= new PhonebookEntry(oldName,oldNumber); entry=read(scanner); } System.out.println("---"); System.out.println(count+" phonebook entries processed."); } }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

please code phonebookApp. other classes have been provided. Please follow direction shown in the pictures. 

 

 

phonenumber class

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class PhoneNumber {

private String num;

public PhoneNumber(String num) {
this.num = num;
}

public String getAreaCode() {
return num.substring(1, 4);
}

public String getExchange() {
return num.substring(5, 8);
}

public String getLineNumber() {
return num.substring(9);
}

public boolean isFreeToll() {
if (getAreaCode().charAt(0) == '8') {
return true;
}
return false;
}

public String toString() {
return "phone number: " + num + "\narea code: " + getAreaCode()
+ "\nexchange: " + getExchange() + "\nline number: "
+ getLineNumber();
}

public boolean equals(PhoneNumber phoneNum) {
if (phoneNum.getAreaCode().compareTo(this.getAreaCode()) == 0
&& phoneNum.getExchange().compareTo(this.getExchange()) == 0
&& phoneNum.getLineNumber().compareTo(this.getLineNumber()) == 0) {
return true;
}
return false;
}

public static String read(Scanner scan) {
if (scan.hasNextLine()) {
return scan.nextLine();
}
return null;
}

public static void main(String[] args) throws FileNotFoundException {

Scanner scan = new Scanner(new File("numbers.text"));

PhoneNumber phoneNumNext, phoneNum = null;

int counts = 0;

String val = PhoneNumber.read(scan);

while (val != null) {

if (phoneNum == null) {
phoneNum = new PhoneNumber(val);

System.out.println(phoneNum + "\nis toll free: "
+ phoneNum.isFreeToll() + "\n");
counts++;
} else {

phoneNumNext = new PhoneNumber(val);


if (phoneNum.equals(phoneNumNext)) {

System.out.println("Duplicate phone number \"("
+ phoneNumNext.getAreaCode() + ")"
+ phoneNumNext.getExchange() + "-"
+ phoneNumNext.getLineNumber() + "\" discovered");

} else {

System.out.println(phoneNumNext + "\nis toll free: "
+ phoneNumNext.isFreeToll() + "\n");
}

counts++;

phoneNum = phoneNumNext;
}

val = PhoneNumber.read(scan);
}
System.out.println("---");
System.out.println(counts + " phone numbers processed.");
}
}

 

 

 

phonebookentry class

 

 

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

class PhonebookEntry
{
private PhoneNumber phoneNumber;
private Name name;

public PhonebookEntry(Name name,PhoneNumber number)
{
this.phoneNumber= number;
this.name=name;
}

public String toString()
{
return name+": "+phoneNumber;
}

public boolean equals(PhonebookEntry otherEntry)
{
if(name.equals(otherEntry.name) && !(phoneNumber.equals(otherEntry.phoneNumber)) )
{
System.out.println("Warning duplicate name encountered \""+ name+": "+phoneNumber+"\" discovered");
return true;
}
else if(phoneNumber.equals(otherEntry.phoneNumber) && name.equals(otherEntry.name))
{
System.out.println("Duplicate phone book entry \""+otherEntry+"\" discovered");
return false;
}
return true;

}

public static PhonebookEntry read(Scanner scanner)
{
if (!scanner.hasNext()) return null;
Name newName = Name.read(scanner);
PhoneNumber newphoneNumber = PhoneNumber.read(scanner);
return new PhonebookEntry(newName, newphoneNumber);
}

public void call()
{
System.out.println("phone book entry: "+name+": "+phoneNumber);
if(phoneNumber.isTollFree())
{
System.out.println("Dialing (toll-free) "+name+": "+phoneNumber);
System.out.println();
}
else
{
System.out.println("Dialing "+name+": "+phoneNumber);
System.out.println("");
}
}

public static void main(String[] args) throws Exception
{
String tempFirst="temp", tempLast="temp", tempNumber="temp";
PhoneNumber oldNumber= new PhoneNumber(tempNumber);
Name oldName= new Name(tempLast,tempFirst);
PhonebookEntry temp= new PhonebookEntry(oldName, oldNumber);
int count=0;
Scanner scanner = new Scanner(new File("phonebook.text"));
PhonebookEntry entry=read(scanner);
while(entry!=null)
{
if(entry.equals(temp))
{
entry.call();
count++;
}
else
{
count++;
}
oldName=entry.name;
oldNumber=entry.phoneNumber;
temp= new PhonebookEntry(oldName,oldNumber);
entry=read(scanner);
}
System.out.println("---");
System.out.println(count+" phonebook entries processed.");

}

}

In this version, you will be adding some inheritance, as well as introducing some collection
classes – ArrayList and Map. The basic operation output is similar to the previous versions,
with the following changes
• Multiple phone numbers are allowed for a phone book entry
• Each phone numbers is accompanied by a description (e.g. 'mobile', 'home', etc.)
• The phonebook array is replaced by a map (which supplies the lookup functionality
directly).
• Reverse lookup goes away
• A command line argument is used to determine the phonebook file to be used
Sample Test Run #1
For example if the file phonebook.text contains:
1 mobile (123) 456-7890
2 home (234)567-8901 work (243) 123-6574
3 cell (345) 678-9012 work (324) 564-0987 fax (987) 234-
David
Harrow
Keith
Jones
Jackie
9823
here is a sample execution of the program:
lookup, quit (1/g) ? 1
last name? Jones
first name? Jackie
Jackie Jones's phone numbers: [cell: (345) 678-9012, work: (324) 564-0987, fax:
(987) 234-9823]
lookup, quit (1/g) ? 1
last name ? Doe
first name? John
-- Name not found
lookup, quit (1/g) ? q
Sample Test Run #2
If the application is run without a command line argument, the output should be:
Usage: RhonekaakARR 'phonebook-filename'
Transcribed Image Text:In this version, you will be adding some inheritance, as well as introducing some collection classes – ArrayList and Map. The basic operation output is similar to the previous versions, with the following changes • Multiple phone numbers are allowed for a phone book entry • Each phone numbers is accompanied by a description (e.g. 'mobile', 'home', etc.) • The phonebook array is replaced by a map (which supplies the lookup functionality directly). • Reverse lookup goes away • A command line argument is used to determine the phonebook file to be used Sample Test Run #1 For example if the file phonebook.text contains: 1 mobile (123) 456-7890 2 home (234)567-8901 work (243) 123-6574 3 cell (345) 678-9012 work (324) 564-0987 fax (987) 234- David Harrow Keith Jones Jackie 9823 here is a sample execution of the program: lookup, quit (1/g) ? 1 last name? Jones first name? Jackie Jackie Jones's phone numbers: [cell: (345) 678-9012, work: (324) 564-0987, fax: (987) 234-9823] lookup, quit (1/g) ? 1 last name ? Doe first name? John -- Name not found lookup, quit (1/g) ? q Sample Test Run #2 If the application is run without a command line argument, the output should be: Usage: RhonekaakARR 'phonebook-filename'
In PB3 your map will have (key, value) pairs as (Name, PhonebookEntry)
Take note: Name has to be unique.
I recommend using TreeMap and implementing for the Name class Comparable<Name>
private Map<Name, PhonebookEntry> map = new TreeMap<Name,
PhonebookEntry> ():
1. Change the PhoneNumber class to have 2 strings: number and description (you can write a
class ExtendedPhoneNumber that inherits your old PhoneNumber class)
2. change the PhonebookEntry class to have an ArrayList of type ExtendedPhoneNumber
3. change the Phonebook class to have a Map with the new PhonebookEntry as the value
type
Transcribed Image Text:In PB3 your map will have (key, value) pairs as (Name, PhonebookEntry) Take note: Name has to be unique. I recommend using TreeMap and implementing for the Name class Comparable<Name> private Map<Name, PhonebookEntry> map = new TreeMap<Name, PhonebookEntry> (): 1. Change the PhoneNumber class to have 2 strings: number and description (you can write a class ExtendedPhoneNumber that inherits your old PhoneNumber class) 2. change the PhonebookEntry class to have an ArrayList of type ExtendedPhoneNumber 3. change the Phonebook class to have a Map with the new PhonebookEntry as the value type
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY