Question: In JAVA SmartPhone add a method public String getTeleponeNeighbor ( ) To calculate the telephone neighbor of any phone number, take the phone number and

In JAVA SmartPhone add a method
public String getTeleponeNeighbor()
To calculate the "telephone neighbor" of any phone number, take the phone number and add one. For example, 805-456-2999 becomes 805-456-3000
Test Case 1
Name: Allan Hancock College Phone: 8059226966
Area code: 805
Prefix: 922
Line number: 6966
Email: hello@hancockcollege.edu
Telephone neighbor: (805)922-6967
---
Name: In-N-Out Burger Phone: 8007861000
Area code: 800
Prefix: 786
Line number: 1000
Email: null
Telephone neighbor: (800)786-1001
---
Name: Costco Wholesale Phone: 8059288459
Area code: 805
Prefix: 928
Line number: 8459
Email: example@costco.com
Telephone neighbor: (805)928-8460
---
Name: Example 1 Phone: 9995999999
Area code: 999
Prefix: 599
Line number: 9999
Email: null
Telephone neighbor: (999)600-0000
---
Name: Example 2 Phone: 9999899999
Area code: 999
Prefix: 989
Line number: 9999
Email: null
Telephone neighbor: (999)990-0000
---public class Demo6
{
public static void main(String[] args)
{
Phone p1= new SmartPhone("Allan Hancock College", 8059226966L, "hello@hancockcollege.edu");
Phone p2= new SmartPhone("In-N-Out Burger", 8007861000L);
Phone p3= new SmartPhone("Costco Wholesale", 8059288459L, "example@costco.com");
Phone p4= new SmartPhone("Example 1",9995999999L);
Phone p5= new SmartPhone("Example 2",9999899999L);
System.out.println(p1);
test(p1);
System.out.println(p2);
test(p2);
System.out.println(p3);
test(p3);
System.out.println(p4);
test(p4);
System.out.println(p5);
test(p5);
}
public static void test(Phone p){
//this will confirm that SmartPhone is a subclass of phone
SmartPhone sp =(SmartPhone)p;
System.out.println("Area code: "+ sp.getAreaCode());
System.out.println("Prefix: "+ sp.getPrefix());
System.out.println("Line number: "+ sp.getLineNumber());
System.out.println("Email: "+ sp.getEmail());
System.out.println("Telephone neighbor: "+ sp.getTeleponeNeighbor());
System.out.println("---");
}}
----public class Phone
{
protected String name;
protected long number;
public Phone(String name, long number){
this.name = name;
this.number = number;
}
public String toString(){
return "I am a phone!";
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!