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 from
public String getAreaCode
returns from
public String getPrefix
returns from
public String getLineNumber
These methods will return parts of the phone number.
Hint: Review the substring method. Test Case
Name: Allan Hancock College Phone:
Area code:
Prefix:
Line number:
Name: InNOut Burger Phone:
Area code:
Prefix:
Line number:
Name: Costco Wholesale Phone:
Area code:
Prefix:
Line number:
public class Demo
public static void mainString args
Phone p new SmartPhoneAllan Hancock College", L;
Phone p new SmartPhoneInNOut Burger", L;
Phone p new SmartPhoneCostco Wholesale", L;
System.out.printlnp;
testp;
System.out.printlnp;
testp;
System.out.printlnp;
testp;
public static void testPhone p
this will confirm that SmartPhone is a subclass of phone
SmartPhone sp SmartPhonep;
System.out.printlnArea code: spgetAreaCode;
System.out.printlnPrefix: spgetPrefix;
System.out.printlnLine number: spgetLineNumber;
System.out.println;
public class Phone
protected String name;
protected long number;
public PhoneString 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
