Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 1.0
This is the forum to discuss the Wrox book Beginning ASP.NET 1.0 with C# by Chris Goode, John Kauffman, Christopher L. Miller, Neil Raybould, S. Srinivasa Sivakumar, Dave Sussman, Ollie Cornes, Rob Birdwell, Matt Butler, Gary Johnson, Ajoy Krishnamoorthy, Juan T. Llibre, Chris Ullman; ISBN: 9780764543708
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 6th, 2006, 10:07 AM
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default chapter 9 exercise

Anyone give me some help on this exericse for chapter 9.

Define an Engine class, whose properties include SerialNo, Rpm, and Name (to be set by the class constructor), and whose methods include SwitchOn and SwitchOff. Now integrate it with the Car class so that you can access these properties and methods from instances of the Car class.

<script runat="server">
Public Class Car
Private _Color As String
Private _Gear As Integer
Private _Ignition As Integer
Private _Engine As Engine

Public Property MyEngine As Engine
 Get
  Return _Engine
 End Get
 Set
  _Engine=value
 End Set
End Property


Sub New()
 _Color="Cold grey Steel"
 _Ignition=IgnitionShape
End Sub

End Class

</script>

thanks.

  #2 (permalink)  
Old April 9th, 2006, 03:56 PM
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's what I came up with. There's some extra stuff in there that you probably don't need (related to color, ignitionshape, etc.), but this demonstrates how to create the engine class and "tie" it to the car class:

<script runat=server language=vb>
Public Class Engine
    Private _SerialNum as Integer
    Private _RPM as Integer
    Private _EngineName as String
    Private _IsOn as Boolean

    Public ReadOnly Property SerialNum as Integer
        Get
            Return _SerialNum
        End Get
    End Property

    Public ReadOnly Property RPM as Integer
        Get
            Return _RPM
        End Get
    End Property

    Public ReadOnly Property EngineName as String
        Get
            Return _EngineName
        End Get
    End Property

    Public ReadOnly Property IsRunning as String
        Get
            If _IsOn then
                Return "The engine is running."
            Else
                Return "The engine is not running."
            End If
        End Get
    End Property

    Public Sub SwitchOn()
        _IsOn = true
    End Sub

    Public Sub SwitchOff()
        _IsOn = False
    End Sub

    Public Sub New()
        _SerialNum = 12223
        _RPM = 130
        _EngineName = "Ferrari 350"
    End Sub

End Class


Public Class Car
    Private _Color as String
    Private _IgnitionShape as Integer

    'This section ties the Engine Class to the Car class
    Private _Engine as Engine

    Public Property MyEngine as Engine
        Get
            Return _Engine
        End Get
        Set
            _Engine = value
        End Set
    End Property


    Public Property Color as string
        get
            Return _Color
        End Get
        Set(value as String)
            _Color = value
        End Set
    End Property
    Public Property IgnitionShape as Integer
        get
            Return _IgnitionShape
        End Get
        Set(value as Integer)
            _IgnitionShape = value
        End Set
    End Property

    Sub New(newIgnitionShape as Integer)
        _IgnitionShape = newIgnitionShape
        _Color = "cold grey steel"
    End Sub

end Class

Sub Page_Load()


    Dim MyCar as New Car(131233123)
    MyCar.MyEngine = New Engine()
    Response.write("<br><br><b>New object 'MyCar' created.</b>")
    Response.write("<br>Color: " & MyCar.Color)
    Response.write("<br>Ignition Shape: " & MyCar.IgnitionShape)
    Response.write("<br>" & MyCar.MyEngine.IsRunning)
    MyCar.MyEngine.SwitchOn
    Response.write("<br>" & MyCar.MyEngine.IsRunning)
    Response.write("<br>Serial Num: " & MyCar.MyEngine.SerialNum)
    Response.write("<br>RPM: " & MyCar.MyEngine.RPM)
    Response.write("<br>Name: " & MyCar.MyEngine.EngineName)


End Sub

</script>
<body>

</body>


 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 5 Exercise 2 diango BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 4 February 1st, 2011 03:24 PM
Chapter 3 - Exercise 3 AndyN BOOK: Beginning Cryptography with Java 3 August 16th, 2006 03:09 PM
Chapter 5 - Exercise 1 scgtman BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 3 May 16th, 2006 08:10 PM
Chapter 3 Exercise 3 Matt WAXON BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 3 July 4th, 2005 02:19 AM
Chapter 8, Exercise 4 cjo BOOK: Beginning ASP.NET 1.0 0 November 3rd, 2003 02:26 PM



All times are GMT -4. The time now is 08:52 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.