justlearning
Member
- Joined
- Dec 11, 2008
- Messages
- 16
- Programming Experience
- Beginner
Hi I am sorry to bother you guys but have a problem. My assignment is as follows:
Okay there are a few things I don't understand. To my knowledge I do not see anything saying that I should have the GUI done but how else would I know that it worked?
Second is the console application the main form or a totally seperate application?
Third I am going to post my code but I am not sure how, in a console program, to get some of this to work. I have done two other very simple console programs.
Anyway, I just watched a two part tutorial called Lesson 6: Object Oriented Programming Fundamentals in the Absolute Beginners series so I think I have a pretty good start. Please look over my code and help me out. I would be forever grateful.
The Rectangle and Box Classes Code
The Console Application Code
For this project, you'll write a set of classes that use apply inheritance principles.
Write a class named Rectangle. This class should have data fields for:
length
width
Also provide the following methods:
A way to get and set each of these fields
a constructor that takes values to initialize the length and width fields
a method that will return the area of the Rectangle (length times width)
a ToString method that will return a description of the Rectangle as a String.
NOTE: Your program will not be drawing the Rectangle, only providing a way to represent it.
Once you have your Rectangle class working correctly, write a child class of Rectangle, named Box. This class should have one additional data field:
height
Also provide the following methods:
a way to get and set the value of height
a constructor that takes values for length, width and height
a method that returns the volume (length times width times height)
a ToString method that returns a String representation of the Box
Write a Console application that lets the user decide if they want to make a Rectangle or a Box. Depending on their answer, prompt them for the necessary values (length and width or length, width and height) and then create an object of that type. Once this is complete, use the ToString method to print a description of the object and then the value of either the area or volume of the object to the Console.
Although not required to look this way, your program output might look like:
Would you like to create a Rectangle or a Box (r or b): b
Please enter the length: 4
Please enter the width: 23
Please enter the height: 3
This object has length: 4 and width: 23 and height: 3
This box has volume: 276
Okay there are a few things I don't understand. To my knowledge I do not see anything saying that I should have the GUI done but how else would I know that it worked?
Second is the console application the main form or a totally seperate application?
Third I am going to post my code but I am not sure how, in a console program, to get some of this to work. I have done two other very simple console programs.
Anyway, I just watched a two part tutorial called Lesson 6: Object Oriented Programming Fundamentals in the Absolute Beginners series so I think I have a pretty good start. Please look over my code and help me out. I would be forever grateful.
The Rectangle and Box Classes Code
VB.NET:
'Parent Class Rectangle
Public Class Rectangle
Protected m_length As Integer
Protected m_width As Integer
Public Sub New(ByVal make As String, ByVal model As String)
m_length = length
m_width = width
End Sub
Public Property length()
Get
Return m_length
End Get
Set(ByVal value)
m_length = value
End Set
End Property
Public Property width()
Get
Return m_width
End Get
Set(ByVal value)
m_width = value
End Set
End Property
Sub New()
MyBase.new()
End Sub
Public Sub New(ByVal length As Double, ByVal width As Double)
MyBase.New()
m_length = length
m_width = width
End Sub
End Class
'Child class
Public Class Box
Inherits Rectangle
Public Sub New()
m_height = height
End Sub
Private m_height As Integer
Public Property height() As Integer
Get
Return m_height
End Get
Set(ByVal value As Integer)
m_height = value
End Set
End Property
End Class
The Console Application Code
VB.NET:
Module Module1
Sub Main()
Dim MyRectangle As New Rectangle
Dim result As String
Dim test As Integer
Console.WriteLine("Would you like to make a Rectangle or a Box? ")
result = Console.ReadLine
If result = Rectangle Then
End If
Console.WriteLine("Please Enter the length: ")
result = Console.ReadLine()
Console.WriteLine("Did this work out correctly?")
test = Console.ReadLine()
End Sub
End Module
Last edited by a moderator: