Wrox Programmer Forums
|
BOOK: Beginning Visual C#
This is the forum to discuss the Wrox book Beginning Visual C#, Revised Edition of Beginning C# for .NET v1.0 by Karli Watson, David Espinosa, Zach Greenvoss, Jacob Hammer Pedersen, Christian Nagel, Jon D. Reid, Matthew Reynolds, Morgan Skinner, Eric White; ISBN: 9780764543821
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 9th, 2003, 05:47 PM
Registered User
 
Join Date: Sep 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 9 Solution???

Does anyone have a sample of what the correct code should look like for Q5 in Chapter 9?
 
Old October 10th, 2003, 10:05 AM
Authorized User
 
Join Date: Aug 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Chris Beach Send a message via AIM to Chris Beach Send a message via MSN to Chris Beach Send a message via Yahoo to Chris Beach
Default

Code:
Car object1=new Car.Compact();
Car object2=new Car.Pickup();
Car object3=new Car.SUV();
Train object4=new Train.DoubleBogey();
Train object5=new Train.Freight();
Train object6=new Train.Passenger();
Console.WriteLine(object1.ToString());
Console.WriteLine(object2.ToString());
Console.WriteLine(object3.ToString());
Console.WriteLine(object4.ToString());
Console.WriteLine(object5.ToString());
Console.WriteLine(object6.ToString());
Is what I've got, with refrence a to Ch09Q04 which is:
Code:
using System;

namespace Vehicle
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    /// 
    public interface IPassengerCarrier
    {
    }

    public interface IHeavyLoadCarrier
    {
    }

    public class Vehicle
    {
        public Vehicle()        //constuctor
        {
        }
    }

    public class Car:Vehicle
    {
        public class Compact:Car,IPassengerCarrier
        {
        }

        public class SUV:Car,IPassengerCarrier
        {
        }

        public class Pickup:Car,IPassengerCarrier,IHeavyLoadCarrier
        {
        }
    }

    public class Train:Vehicle
    {
        public class Passenger:Train,IPassengerCarrier
        {
        }

        public class Freight:Train,IHeavyLoadCarrier
        {
        }

        public class DoubleBogey:Train
        {
        }

    }
}
Which looks about right:)

 
Old October 15th, 2003, 05:15 PM
Registered User
 
Join Date: Sep 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, although that is good for number 4, it still doesn't help me much with number 5
 
Old October 16th, 2003, 04:47 AM
Authorized User
 
Join Date: Aug 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Chris Beach Send a message via AIM to Chris Beach Send a message via MSN to Chris Beach Send a message via Yahoo to Chris Beach
Default

code for 5 is at the top, but of course that makes no sense without 4 which is at the bottom.

 
Old November 19th, 2003, 11:06 PM
Registered User
 
Join Date: Nov 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi. i don't understand Q(5) of Chapter 9, to include AddPassenger () function. Pls anyone help me. Thx.

 
Old November 20th, 2003, 06:09 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Not everyone has the book, so maybe you can post the question and some context as well. You could also decide to start a new thread, so your question gets a bit more exposure than when you continue an old thread.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old March 9th, 2004, 05:24 AM
Registered User
 
Join Date: Mar 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Public class Vehicle
Public class Car
Public class Train

should be:

Public abstract class Vehicle
Public abstract class Car:Vehicle
Public abstract class Train:Vehicle

As the UML diagram uses italic writing for these headings; they cannot be instantiated, only inherited.

 
Old September 18th, 2006, 07:51 PM
Registered User
 
Join Date: Sep 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I know DanF is correct, here is what I did:

using System;
using System.Collections.Generic;
using System.Text;

namespace Vehicles
{
    public abstract class Vehicle
    {
    }

    public interface IPassengerCarrier
    {
        int AddPassengers();
    }

    public interface IHeavyLoadCarrier
    {
    }

    public abstract class Car : Vehicle
    {
    }

    public abstract class Train : Vehicle
    {
    }

    public class Compact : Car, IPassengerCarrier
    {
        public int AddPassengers()
        {
            return 2;
        }
    }

    public class Pickup : Car, IPassengerCarrier, IHeavyLoadCarrier
    {
        public int AddPassengers()
        {
            return 4;
        }
    }

    public class SUV : Car, IPassengerCarrier
    {
        public int AddPassengers()
        {
            return 6;
        }
    }
    public class PassengerTrain : Train, IPassengerCarrier
    {
        public int AddPassengers()
        {
            return 8;
        }
    }

    public class FreightTrain : Train, IHeavyLoadCarrier
    {
    }

    public class DoubleBogey : Train, IHeavyLoadCarrier
    {
    }
}

Then for the finishing code, I added a simple function to return an int value of passengers:

using System;
using System.Collections.Generic;
using System.Text;
using Vehicles;

namespace Traffic
{
    class Program
    {
        static void Main(string[] args)
        {
            Compact chevyChevette = new Compact();
            Pickup nissanFrontier = new Pickup();
            SUV chryslerTrailBlazer = new SUV();
            PassengerTrain myPassengerTrain = new PassengerTrain();

            int objA = chevyChevette.AddPassengers();
            int objB = nissanFrontier.AddPassengers();
            int objC = chryslerTrailBlazer.AddPassengers();
            int objD = myPassengerTrain.AddPassengers();

            Console.WriteLine("My Chevette can carry {0} passengers.\n", objA.ToString());
            Console.WriteLine("My Frontier can carry {0} passengers.\n", objB.ToString());
            Console.WriteLine("My Trail Blazer can carry {0} passengers.\n", objC.ToString());
            Console.WriteLine("My Train can carry {0} passengers.\n", objD.ToString());
        }
    }
}
 
Old September 19th, 2006, 11:17 AM
Registered User
 
Join Date: Sep 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is there a better way to code my above sample?

I don't think the code Chris Beach will work if Vehicle, Car and Train are 'abstract' classes.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 6 (A Sample Collaborative Solution) Dave_W BOOK: Professional SharePoint 2007 Development ISBN: 978-0-470-11756-9 3 February 25th, 2009 08:58 AM
Need Solution to Chapter 20 Spasticus BOOK: Ivor Horton's Beginning Visual C++ 2005 1 January 26th, 2008 08:12 AM
Solution: Chapter 4, Table 2 Problems amenne20 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 September 22nd, 2006 11:50 AM
Solution to exercise 7, Chapter 2 Nick Y BOOK: Ivor Horton's Beginning Visual C++ 2005 0 May 28th, 2006 04:28 AM
solution 1 in exercises in chapter 6 juan_forum BOOK: Beginning Java 2 0 September 16th, 2005 11:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.