TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Prime b
NA
810
346k
Inheritance
Feb 14 2012 8:52 PM
Create a class named Tape that includes fi elds for length and
width in inches and properties for each fi eld. 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 fi elds. Derive two subclasses—
VideoTape and AdhesiveTape. Th e VideoTape class
includes an integer fi eld to hold playing time in minutes and
a property for the fi eld. Th e AdhesiveTape class includes an
integer fi eld that holds a stickiness factor—a value restricted
to fall in the range of 1 to 10—and a property for the fi eld.
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 AdhesiveTape
class stickiness factor.
I think I didn't do it correctly, could you look at it? please
=============================MAIN METHOD========================
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(tape1.StickFactor+" "+" "+tape1.Length+" "+tape1.Width);
tape2.PlayingTime = 20;
tape2.Length = 2;
tape2.Width = 5;
Console.WriteLine(tape2.PlayingTime + " " + tape2.Length + " " + tape2.Width);
tape3.Length = 41;
tape3.Width = 51;
Console.WriteLine(tape3.Length +" "+ tape3.Width);
}
}
===========================PARENT CLASS================================
namespace TapeDemo
{
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);
}
}
}
==========================Child class 1=============================
namespace TapeDemo
{
class VideoTape : Tape
{
int playingTime;
public int PlayingTime
{
get { return playingTime; }
set { playingTime = value; }
}
}
=========================Child class 2===============================
namespace TapeDemo
{
class AdhesiveTape : Tape
{
int stickFactor;
public int StickFactor
{
get { return stickFactor; }
set
{
if ((stickFactor > 1) && (stickFactor < 10))
{
stickFactor = value;
}
else
{
Console.WriteLine("WRONG NUMBER");
}
}
}
}
}
Reply
Answers (
9
)
Project-2:Phase - Designing
Tab control colour change in C# .net