Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create an application class named LetterDemo that instantiates objects of two classes named Letter and CertifiedLetter and that demonstrates all their methods. The classes are

Create an application class named LetterDemo that instantiates objects of two classes named Letter and CertifiedLetter and that demonstrates all their methods.

The classes are used by a company to keep track of letters they mail to clients. The Letter class includes auto-implemented properties for the Name of the recipient and the Date mailed (stored as strings).

Next, include a ToString() method that overrides the Object classs ToString() method and returns a string that contains the name of the class (using GetType()) and the Letters data field values.

Create a child class named CertifiedLetter that includes an auto-implemented property TrackingNumber (of type string) that holds a tracking number for the letter.

What I have:

using System; //application namespace namespace LetterDemo { class Letter // definition of class Letter { // auto-implemented properties public string Name { get; set; } public string Date { get; set; } // override ToString public override string ToString() { string output =String.Format("Class Name: {0} | Recipient" +" Name: {1} | Date: {2} ",this.GetType(), Name, Date); return output;//return output } } // derived class class CertifiedLetter : Letter { // Auto-implemented property for tracking number public int TrackingNumber { get; set; } // override the ToString method public override string ToString() { string output =String.Format("Class Name: {0} | Recipient" +" Name: {1} | Date: {2} | " +"Tracking Number: {3} ",this.GetType(), Name, Date,TrackingNumber); return output; } } class Program //Test class { //entry point of application , main method static void Main(string[] args) { // create object of Letter Letter L = new Letter(); L.Name = "John"; //set Name L.Date = "12 November 2017"; //set Date // create object of CertifiedLetter CertifiedLetter CL = new CertifiedLetter(); CL.Name = "Mark";//set Name CL.Date = "11 November 2017"; //set Date CL.TrackingNumber = 123121; Console.WriteLine(L.ToString());//print details Console.WriteLine(CL.ToString());//print details Console.ReadKey();//used to hold the screen

Error I get:

Compilation failed: 4 error(s), 0 warnings NtTestf891301d.cs(10,8): error CS0246: The type or namespace name `Letter' could not be found. Are you missing `LetterDemo' using directive? NtTestf891301d.cs(11,8): error CS0841: A local variable `letter' cannot be used before it is declared NtTestf891301d.cs(12,8): error CS0841: A local variable `letter' cannot be used before it is declared NtTestf891301d.cs(13,24): error CS0841: A local variable `letter' cannot be used before it is declared

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

7. Define cultural space.

Answered: 1 week ago

Question

8. Describe how cultural spaces are formed.

Answered: 1 week ago