C
C#•8mo ago
zehel

Program that uses auto-implemented properties, overriding ToString(), and a child class

Hello guys. I'm going to try to be as clear as possible, but bear with me. I need to make a program that: 1. Create a class named LetterDemo that instantiates objects of two classes (named Letter and Certified Letter) 2. The Letter class includes auto-implemented properties for name of the letter recipient and the date is was mailed. 3. In the Letter class, also create a ToString() method that overrides the Object class's ToString() method and retuns a string that contains the name of the class (using GetType() and the Letter's data field values. 4. Create a child class named CertifiedLetter that contains an auto-implemented property that holds a tracking number for the letter. (I am assuming this would be given if the user indicates that the letter is certified.) I have the layout figured out, but I am getting really lost in the sauce with how the classes and objects need to interact with each other.
class LetterDemo
{
class Letter
{
public string Name { get; set; }
public string DateMailed {get; set; }

public static string StringMessage(string name, string dateMailed, trackingnumber?)
{
//override ToString()
return Letter data as output for user at the end
}
}
class CertifiedLetter : Letter
{
public static int TrackingNumber()
{
Random rnd = new Random();
int newNum = rnd.Next(1000, 9999);
string trackingNumber = newNum.ToString();
return trackingNumber;
}
}
static void Main()
{
//create letter object
//get input and create .Name and .DateMailed
//prompt y or n for isCertified and test with if()
//display LetterMessage()
)
class LetterDemo
{
class Letter
{
public string Name { get; set; }
public string DateMailed {get; set; }

public static string StringMessage(string name, string dateMailed, trackingnumber?)
{
//override ToString()
return Letter data as output for user at the end
}
}
class CertifiedLetter : Letter
{
public static int TrackingNumber()
{
Random rnd = new Random();
int newNum = rnd.Next(1000, 9999);
string trackingNumber = newNum.ToString();
return trackingNumber;
}
}
static void Main()
{
//create letter object
//get input and create .Name and .DateMailed
//prompt y or n for isCertified and test with if()
//display LetterMessage()
)
Any help with at least a starting point or how to set up the objects and child class would be a life saver. I know I am probably overcomplicating this in my head. Thank you!
1 Reply
Pobiega
Pobiega•8mo ago
First things first, should DateMailed really be a string, and not a DateTimeOffset or DateOnly? 🙂 Other than that, you're pretty close. The certified letter doesnt have a property to store its tracking number however and you didnt actually override the ToString method in either letter