Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

language is java. Please fix the code so it can run. I cannot run it on a web compiler or jGRASP. Please make it work

language is java. Please fix the code so it can run. I cannot run it on a web compiler or jGRASP. Please make it work on JGrasp first then copy and paste the classes seperately please. Also, please seperate the phone, businessphone, and phonemain classes into seperate java files.

Below is a completed code but the input is supposed to be (not real person or number btw):

Alyssa 270 320 3344

------------------------------------------

import java.io.File; import java.util.Scanner; import java.util.Arrays; class Phone implements Comparable { String name; int areaCode; int exchangeNumber; int number; public Phone(String name, int areaCode, int exchangeNumber, int number) { this.name = name; this.areaCode = areaCode; this.exchangeNumber = exchangeNumber; this.number = number; } public void setName(String name) { this.name = name; } public void setAreaCode(int areaCode) { this.areaCode = areaCode; } public void setExchangeNumber(int exchangeNumber) { this.exchangeNumber = exchangeNumber; } public void setNumber(int number) { this.number = number; } public String getName() { return (this.name); } public int getAreaCode() { return (this.areaCode); } public int getExchangeNumber() { return (this.exchangeNumber); } public int getNumber() { return (this.number); } public String toString() { return areaCode+"-"+exchangeNumber+"-"+number; } public int compareTo(Phone p){ return name.compareTo(p.getName()); } } class BusinessPhone extends Phone { int extension; public BusinessPhone(String name, int areaCode, int exchangeNumber, int number, int extension) { super(name, areaCode, exchangeNumber, number); this.extension = extension; } public void setExtension(int extension) { this.extension = extension; } public int getExtension() { return (this.extension); } public String toString() { return super.toString()+" : "+extension; } public int compareTo(BusinessPhone p){ return name.compareTo(p.getName()); } } public class PhoneMain { static void sortByName(Phone p[]) { Arrays.sort(p); } static void sortByName(BusinessPhone b[]) { Arrays.sort(b); } static void searchByName(BusinessPhone b[],String sname,Phone p[]) { for(int i=0;i 0) { if(count%3!=0) { if(count%3==2) { //try{ number=line; //System.out.println(line); String[] num=number.split(" "); if(num.length==3) { phonenumbers[pp]=new Phone(name,Integer.parseInt(num[0]),Integer.parseInt(num[1]),Integer.parseInt(num[2])); pp++; } else{ businessphonenumbers[bp]=new BusinessPhone(name,Integer.parseInt(num[0]),Integer.parseInt(num[1]),Integer.parseInt(num[2]),Integer.parseInt(num[3])); bp++; } //}catch(Exception e){ //} } else{ name=line; } } } //System.out.println(); } sc.close(); Scanner in=new Scanner(System.in); String sname=in.nextLine(); in.nextLine(); String sphone=in.nextLine(); System.out.println(""); sortByName(phonenumbers); sortByName(businessphonenumbers); System.out.println("Phone Numbers: "); for(int i=0;i 

------------------------------------------

input.txt file:

Daniel 270 345 6789 Phillip 270 745 9000 123 Jamal 502 444 5555 Christopher 270 567 800 200 Charless 270 313 2400 23 Eric 615 345 7890 123 Alyssa 270 320 3344

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago