Question: Add three methods to SmartPhone: / / returns 8 0 5 from 8 0 5 9 2 2 6 9 6 6 public String getAreaCode

Add three methods to SmartPhone:
//returns 805 from 8059226966
public String getAreaCode()
//returns 922 from 8059226966
public String getPrefix()
//returns 6966 from 8059226966
public String getLineNumber()
These methods will return parts of the phone number.
Hint: Review the substring method. Test Case 1
Name: Allan Hancock College Phone: 8059226966
Area code: 805
Prefix: 922
Line number: 6966
---
Name: In-N-Out Burger Phone: 8007861000
Area code: 800
Prefix: 786
Line number: 1000
---
Name: Costco Wholesale Phone: 8059288459
Area code: 805
Prefix: 928
Line number: 8459
---public class Demo4
{
public static void main(String[] args)
{
Phone p1= new SmartPhone("Allan Hancock College", 8059226966L);
Phone p2= new SmartPhone("In-N-Out Burger", 8007861000L);
Phone p3= new SmartPhone("Costco Wholesale", 8059288459L);
System.out.println(p1);
test(p1);
System.out.println(p2);
test(p2);
System.out.println(p3);
test(p3);
}
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("---");
}} 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!