Can someone tell me if I am on the right track?
Can someone tell me if I am on the right track with these instructions?
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).
Create a child class named CertifiedLetter that includes an auto-implemented property TrackingNumber (of type string) that holds a tracking number for the letter.
Next, include a ToString() method that overrides the Object class’s ToString() method and returns a string that contains the name of the class (using GetType()) and the respective class's data field values. Use default, empty constructor for both classes.
1 Reply
You're starting to get there. Some things to pay attention to:
* Classes should be declared directly in a namespace: you can't declare a class inside a method
* Classes are delcared with
class Letter
, not class Letter()
* The instructions say to use auto-implemented properties
* The instructions say what ToString
should do, specifically
* The instructions say that you should test all of the methods of your classes
* The C# syntax for declaring a variable is e.g. Letter letter
. To assign a new instance of Letter
to that variable, you do e.g letter = new Letter()
. To do the two together, you do e.g. Letter letter = new Letter()
There are lots of typos in your code. If you try to compile your code, the compiler will tell you what the mistakes are
Talking about non-empty ctors, static create methods, required/init properties, etc, is not relevant or helpful. OP is obviously just starting out
Same!