Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an application class named LetterDemo that instantiates objects of two cl

ID: 3714392 • Letter: C

Question

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 Nane of the recipient and the Date mailed (stored as strings). Next, include a ToString() method that overrides the Object class's ToStringC) method and returns a string that contains the name of the class (using GetType) ) and the Letter 's 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.

Explanation / Answer

Answer :-

As I have answered this question in JAVA so i have used getClass() method instead of getType().

So in C# you can use getType() in place of getClass() , it will work fine.

So here are the classes :-

1. Letter

public class Letter {

private String name;

private String date;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getDate() {

return date;

}

public void setDate(String date) {

this.date = date;

}

public Letter(String name, String date) {

super();

this.name = name;

this.date = date;

}

public String toString() {

return "Letter [name=" + name + ", date=" + date + "]"+"class name = "+this.getClass();

}

}

2 . CertifiedLetter

public class CertifiedLetter extends Letter {

private String trackingnumber;

public String getTrackingnumber() {

return trackingnumber;

}

public void setTrackingnumber(String trackingnumber) {

this.trackingnumber = trackingnumber;

}

public CertifiedLetter(String name, String date, String trackingnumber) {

super(name, date);

this.trackingnumber = trackingnumber;

}

public String toString() {

return "CertifiedLetter [trackingnumber=" + trackingnumber + ", toString()=" + super.toString() + "]";

}

}

3. LetterDemo

public class LetterDemo {

public static void main(String[] args) {

Letter letter=new Letter("Raj", "28/03/2018");

CertifiedLetter cLetter=new CertifiedLetter("Raj", "28/03/2018","TN204");

System.out.println(letter);

System.out.println(cLetter);

}

}

OUTPUT:-

Letter [name=Raj, date=28/03/2018]class name = class Letter
CertifiedLetter [trackingnumber=TN204, toString()=Letter [name=Raj, date=28/03/2018]class name = class CertifiedLetter]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote