Assignment Description Build an abstract class to represent a generic “phone” ob
ID: 3828789 • Letter: A
Question
Assignment Description
Build an abstract class to represent a generic “phone” object. Derive “analog” and “digital” phones from the general “phone” object. Derive “smart” phone from the “digital” phone object. Subsequently, create a driver (or set of drivers) to test each of these objects.
Abstract Class Design: Phone
Design an abstract class “Phone” as a representation of a generic phone. At minimum, it should be able to do the following:
Accept calls (leave abstract)
Make calls (leave abstract)
End calls (provide an appropriate message to be used by derived classes)
Class Design: Analog Phone
Design an “analog phone” Class as a child of the “Phone” class. In addition to implementing the abstract methods (e.g. providing appropriate messages), also do at minimum:
• Override for ending calls -> allow users to end calls by “slamming” the actual phone receiver
Class Design: Digital Phone
Design a “digital phone” Class as a child of the “Phone” class. In addition to implementing the abstract methods, also do at minimum:
• A way to get call history from latest to oldest
- Call history should include both accepted calls and calls that were made from the phone
Class Design: Smart Phone
Design a “smart phone” Class as a child of the “Digital Phone” class. In addition to implementing the abstract methods, also do at minimum:
• A way to store and get voice mails
- Users should get voice mails from oldest stored voice mail to most recent voice mail
Driver Classes
Your driver class should do at minimum:
Instantiate every class
Test every getter and setter (ensure validation)
Test every public method to verify it works correctly
Explanation / Answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AbstractClassDemo
{
public abstract class Phone
{
public abstract void acceptCalls();
public abstract void makeCalls();
public virtual void endCalls()
{
Console.WriteLine("End Calls");
}
}
public class AnalogPhone : Phone
{
public override void acceptCalls()
{
Console.WriteLine("Analog Phone: Accepting Calls");
}
public override void makeCalls()
{
Console.WriteLine("Analog Phone: Making Calls");
}
public override void endCalls()
{
Console.WriteLine("Analog Phone: Ending Calls");
}
}
public class DigitalPhone : Phone
{
string callHistory = "ABC";
public override void acceptCalls()
{
Console.WriteLine("Digital Phone: Accepting Calls");
}
public override void makeCalls()
{
Console.WriteLine("Digital Phone: Making Calls");
}
public override void endCalls()
{
Console.WriteLine("Digital Phone: Ending Calls");
}
public string getCallHistory
{
get
{
return callHistory;
}
}
}
public class SmartPhone : DigitalPhone
{
string voiceMails = "DEF";
public override void acceptCalls()
{
Console.WriteLine("Smart Phone: Accepting Calls");
}
public override void makeCalls()
{
Console.WriteLine("Smart Phone: Making Calls");
}
public override void endCalls()
{
Console.WriteLine("Smart Phone: Ending Calls");
}
public string getVoiceMails
{
get
{
return voiceMails;
}
set
{
voiceMails = value;
}
}
}
class DriverClass
{
static void Main(string[] args)
{
AnalogPhone analogPhoneObj = new AnalogPhone();
DigitalPhone digitalPhoneObj = new DigitalPhone();
SmartPhone smartPhoneObj = new SmartPhone();
string callHistory;
string voiceMails;
analogPhoneObj.acceptCalls();
analogPhoneObj.makeCalls();
analogPhoneObj.endCalls();
Console.WriteLine(Environment.NewLine);
digitalPhoneObj.acceptCalls();
digitalPhoneObj.makeCalls();
digitalPhoneObj.endCalls();
callHistory = digitalPhoneObj.getCallHistory;
Console.WriteLine("Digital Phone: Call History " + callHistory);
Console.WriteLine(Environment.NewLine);
smartPhoneObj.acceptCalls();
smartPhoneObj.makeCalls();
smartPhoneObj.endCalls();
voiceMails = smartPhoneObj.getVoiceMails;
Console.WriteLine("Smart Phone: Voice Mails " + voiceMails);
Console.ReadLine();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.