Write a program to define a class College BUS and a class BusEngine .Let the CollegeBus class contain BusEngine .The BusEngine should be started at the College Campus and stopped after reaching the destination (say Y ) .Let the speed and the distance be read.The Program should throw an exception when the CollegeBus tries to travel beyond destination or speed increase beyond 100 kmper hour. Develop the application in C#.
i am not understanding my mistake
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class CollegeBus
{
public static int speed;
public static float distance;
public CollegeBus(int s, float d)
{
speed = s;
distance = d;
}
}
public class Engine : CollegeBus
{
string str1;
string str2;
public Engine(string s1, string s2)
: base(speed, distance)
{
str1 = s1;
str2 = s2;
Console.WriteLine("Source is {0} and destination is {0}",s1,s2);
if (distance > 30)
throw new DistanceExceededException();
if (speed > 100)
throw new SpeedExceededException();
}
}
class Travel
{
public static void Main()
{
CollegeBus b=new CollegeBus(40,20);
//Engine e=new Engine("X","Y");
b.Engine.str1=40;
b.Engine.str2=20;
}
Loading
Siva Ganesh RongalaPosted Apr 25, 2013, 10:16 AM
here you are creating base class Constructor
So only base Class Memory Will be Crated.
b.Engine.str1=40;
b.Engine.str2=20;
Now the Above Line is Completely Wrong
Why because b is not having any variable name or inner class name with Engine
So we can't call with that name.
So first assign value of speed and distance
and then create object for Engine
next we can't call str1; str2;
because of access specifier please change access specifier for that.
Jibin MatthewPosted Apr 25, 2013, 10:32 AM
Thank you :)