 |
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
|
|
|
|

October 9th, 2003, 05:47 PM
|
|
Registered User
|
|
Join Date: Sep 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Chapter 9 Solution???
Does anyone have a sample of what the correct code should look like for Q5 in Chapter 9?
|
|

October 10th, 2003, 10:05 AM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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:)
|
|

October 15th, 2003, 05:15 PM
|
|
Registered User
|
|
Join Date: Sep 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks, although that is good for number 4, it still doesn't help me much with number 5
|
|

October 16th, 2003, 04:47 AM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
code for 5 is at the top, but of course that makes no sense without 4 which is at the bottom.
|
|

November 19th, 2003, 11:06 PM
|
|
Registered User
|
|
Join Date: Nov 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi. i don't understand Q(5) of Chapter 9, to include AddPassenger () function. Pls anyone help me. Thx.
|
|

November 20th, 2003, 06:09 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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.
|
|

March 9th, 2004, 05:24 AM
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

September 18th, 2006, 07:51 PM
|
|
Registered User
|
|
Join Date: Sep 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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());
}
}
}
|
|

September 19th, 2006, 11:17 AM
|
|
Registered User
|
|
Join Date: Sep 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|
 |