Question

Include outputs. Write a C# console application named Tape that includes fields for length and width...

Include outputs. Write a C# console application named Tape that includes fields for length and width in inches and properties for each field. Also include a ToString() method that returns a string constructed from the return value of the object's GetType() method and the values of the length and width fields. Derive two subclasses - VideoCassetteTape and AdhesiveTape. The VideoCassetteTape class includes an integer field to hold playing time in minutes - a value from 1 to 180 - and a property for the field. The AdhesiveTape class includes an integer field that holds a stickiness factor - a value from 1 to 10 - and a property for the field. Write a program that instantiates one object of each of the three classes, and demonstrate that all of each class's methods work correctly. Be sure to use valid and invalid values when testing the numbers you can use to set the properties of each class.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

namespace TapeDemo

{

class Program

{

static void Main(string[] args)

{

AdhesiveTape tape1 = new AdhesiveTape();

VideoTape tape2 = new VideoTape();

Tape tape3 = new Tape();

tape1.StickFactor = 2;

tape1.Length = 20;

tape1.Width = 10;

Console.WriteLine("{0} {1}", tape1, tape1.StickFactor);

tape2.PlayingTime = 20;

tape2.Length = 2;

tape2.Width = 5;

Console.WriteLine("{0} {1}", tape2, tape2.PlayingTime);

tape3.Length = 41;

tape3.Width = 51;

Console.WriteLine(tape3);

// now an invalid one

AdhesiveTape tape4 = new AdhesiveTape();

tape4.StickFactor = 11; // too big

tape4.Length = 30;

tape4.Width = 15;

Console.WriteLine("{0} {1}", tape4, tape4.StickFactor);

}

}

class Tape

{

private int length;

private int width;

public int Length

{

get { return length; }

set { length = value; }

}

public int Width

{

get { return width; }

set { width = value; }

}

public override string ToString()

{

return (GetType() + " " + length + " " + width);

}

  

}

class AdhesiveTape : Tape

{

int stickFactor = 1; // use a default of 1 as 0 would be invalid

public int StickFactor

{

get { return stickFactor; }

set

{

if ((value >= 1) && (value <= 10)) // test value here, not stickFactor

{

stickFactor = value;

}

else

{

Console.WriteLine("WRONG NUMBER FOR STICKINESS FACTOR");

}

}

}

}

class VideoTape : Tape

{

int playingTime;

public int PlayingTime

{

get { return playingTime; }

set { playingTime = value; }

}

}

}

Add a comment
Know the answer?
Add Answer to:
Include outputs. Write a C# console application named Tape that includes fields for length and width...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using C#: Create an application class named BillDemo that instantiates objects of two classes named Bill...

    Using C#: Create an application class named BillDemo that instantiates objects of two classes named Bill and OverdueBill, and that demonstrates all their methods. The Bill class includes auto-implemented properties for the name of the company or person to whom the bill is owed and for the amount due. Also, include a ToString() method and returns a string that contains the name of the class (using GetType()) and the Bill’s data fields values. Create a child class named OverdueBill that...

  • Using C# Create an application class named LetterDemo that instantiates objects of two classes named Letter...

    Using C# 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 class’s ToString() method and returns a string that contains the name of...

  • dateInformation class. visual basic. Crate a class called DateInformation that includes three pieces of information as...

    dateInformation class. visual basic. Crate a class called DateInformation that includes three pieces of information as intense variable- a month(type Integer), a day(type Integer) and year (type Integer). Your class should provide properties that enables a client of the class to get and set the month, day, year values.The set acessor should perform validation and throw exception for invalid values. You class should have a constructor that initializes the three instances variables and uses the class's property to set each...

  • Write the C# code and make a screenshot of the output according to tasks given below:...

    Write the C# code and make a screenshot of the output according to tasks given below: Create a class named Prism with protected data fields named height and volume (Use double data type for the fields) [5 points] Include public properties for each field. The Height and Volume properties should have get and set accessors. [5 points] Add default constructor which sets the value of Height and Volume properties to 1 and 1 respectively. [5 points] Add overloading constructor which...

  • Graded Exercise Create a class named Student. A Student has fields for an ID number, number...

    Graded Exercise Create a class named Student. A Student has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point...

  • WRITING METHODS 1. Implement a method named surface that accepts 3 integer parameters named width, length,...

    WRITING METHODS 1. Implement a method named surface that accepts 3 integer parameters named width, length, and depth. It will return the total surface area (6 sides) of the rectangular box it represents. 2. Implement a method named rightTriangle that accepts 2 double arameters named sideA and hypotenuseB. The method will return the length of the third side. NOTE To test, you should put all of these methods into a ‘MyMethods’ class and then write an application that will instantiate...

  • java Write a class named Car that has the following fields: • yearModel: The yearModel field...

    java Write a class named Car that has the following fields: • yearModel: The yearModel field is an int that holds the car's year model. • make: The make field is a String object that holds the make of the car. • speed: The speed field is an int that holds the car's current speed. In addition, the class should have the following methods: • Constructor: The constructor should accept the car's year model and make as arguments. These values...

  • Room Class....... in JAVA!!!!! Write a class named Room that has the following fields: Length: Double...

    Room Class....... in JAVA!!!!! Write a class named Room that has the following fields: Length: Double variable that holds the rooms length(in feet). Breadth: The double variable that holds the rooms breadth(in feet). Height: Double variable that holds rooms height in feet. Color: String object that holds the color you want the room to be painted with. The class should have a constructor to initialize the fields for a particular instance (or object) of the class as given: All double...

  • Write a class called Shelf that contains instance data that represents the length, breadth, and capacity...

    Write a class called Shelf that contains instance data that represents the length, breadth, and capacity of the shelf. Also include a boolean variable called occupied as instance data that represents whether the shelf is occupied or not. Define the Shelf constructor to accept and initialize the height, width, and capacity of the shelf. Each newly created Shelf is vacant (the constructor should initialize occupied to false). Include getter and setter methods for all instance data. Include a toString method...

  • Make a LandTract class with the following fields: LandTract is a rectangle. * length - an...

    Make a LandTract class with the following fields: LandTract is a rectangle. * length - an int containing the tract's length * width - an int containing the tract's width The class should have a constructor with two arguments length and width and assign these to the class variables. Now define a Copy Constructor: The constructor that you will write will be a copy constructor that uses the parameter LandTract object to make a duplicate LandTract object, by copying the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT