f



Need Help with this problem

I am in this programming class and need help on this problem:

- Defines a Ruby class, Vehicle, with attributes weight, length width
and height. The Vehicle class should have a class variable counts the
number of vehicle objects created.
- Define three subclasses, landvehicle, watervehicle, and airvehicle so
they inherit the attributes of the vehicle class and so that each has
some attributes of its own, numberofwheels for landvehicles, keeldepth
for watervehicles, and maxairspeed or airvehicles
- creates 1 landvhicle objects, 2 watervehicle objects and 3 airvehicle
objects, use [ constructors ] in each subclass to assign initial values
of numberofwheels, keeldepth and maxairspeed to the appropriate objects.
You should invent the actual values to use when these objects are
created
- Display the number of vehicle objects created then ends.

attached is what i did, i was wondering if its correct
-- 
Posted via http://www.ruby-forum.com/.

0
ghosttilt (3)
10/12/2009 9:38:42 PM
comp.lang.ruby 48886 articles. 0 followers. Post Follow

4 Replies
517 Views

Similar Articles

[PageSpeed] 13

Ghost Alpha wrote:
> I am in this programming class and need help on this problem:
> 
> - Defines a Ruby class, Vehicle, with attributes weight, length width
> and height. The Vehicle class should have a class variable counts the
> number of vehicle objects created.
> - Define three subclasses, landvehicle, watervehicle, and airvehicle so
> they inherit the attributes of the vehicle class and so that each has
> some attributes of its own, numberofwheels for landvehicles, keeldepth
> for watervehicles, and maxairspeed or airvehicles
> - creates 1 landvhicle objects, 2 watervehicle objects and 3 airvehicle
> objects, use [ constructors ] in each subclass to assign initial values
> of numberofwheels, keeldepth and maxairspeed to the appropriate objects.
> You should invent the actual values to use when these objects are
> created
> - Display the number of vehicle objects created then ends.
> 
> attached is what i did, i was wondering if its correct

here is the link to the

http://demo.ovh.org/en/8c779e3d297b9839114ac4c737c22065/
-- 
Posted via http://www.ruby-forum.com/.

0
ghosttilt (3)
10/12/2009 9:43:04 PM
> Ghost Alpha wrote:
> > I am in this programming class and need help on this problem:
> >
> > - Defines a Ruby class, Vehicle, with attributes weight, length width
> > and height. The Vehicle class should have a class variable counts the
> > number of vehicle objects created.
> > - Define three subclasses, landvehicle, watervehicle, and airvehicle
> so
> > they inherit the attributes of the vehicle class and so that each has
> > some attributes of its own, numberofwheels for landvehicles,
> keeldepth
> > for watervehicles, and maxairspeed or airvehicles
> > - creates 1 landvhicle objects, 2 watervehicle objects and 3
> airvehicle
> > objects, use [ constructors ] in each subclass to assign initial
> values
> > of numberofwheels, keeldepth and maxairspeed to the appropriate
> objects.

You aren't using constructors to define numberofwheels, keeldepth, and
maxairspeed.  In your code they are simply constant functions.

> > You should invent the actual values to use when these objects are
> > created
> > - Display the number of vehicle objects created then ends.
> >
> > attached is what i did, i was wondering if its correct
> 
> here is the link to the
> 
> http://demo.ovh.org/en/8c779e3d297b9839114ac4c737c22065/
> --
> Posted via http://www.ruby-forum.com/.



0
walton (57)
10/12/2009 10:21:17 PM
Walton Hoops wrote:
>> keeldepth
>> > for watervehicles, and maxairspeed or airvehicles
>> > - creates 1 landvhicle objects, 2 watervehicle objects and 3
>> airvehicle
>> > objects, use [ constructors ] in each subclass to assign initial
>> values
>> > of numberofwheels, keeldepth and maxairspeed to the appropriate
>> objects.
> 
> You aren't using constructors to define numberofwheels, keeldepth, and
> maxairspeed.  In your code they are simply constant functions.

can you show me the correct way?

-- 
Posted via http://www.ruby-forum.com/.

0
ghosttilt (3)
10/12/2009 10:48:21 PM
Ghost Alpha wrote:
> Walton Hoops wrote:
>>> keeldepth
>>> > for watervehicles, and maxairspeed or airvehicles
>>> > - creates 1 landvhicle objects, 2 watervehicle objects and 3
>>> airvehicle
>>> > objects, use [ constructors ] in each subclass to assign initial
>>> values
>>> > of numberofwheels, keeldepth and maxairspeed to the appropriate
>>> objects.
>> 
>> You aren't using constructors to define numberofwheels, keeldepth, and
>> maxairspeed.  In your code they are simply constant functions.
> 
> can you show me the correct way?

Hi Ghost Alpha,

It looks like you forgot to add initialize methods to your sub-classes

you wrote:

class Land < Vehicle
  def numberofwheels
    "#@numberofwheels Numberofwheels is four"
  end
end

That doesn't do what you need it to do. What if I wanted to create a 10 
wheel truck? I would be out of luck, because I can only have four wheels 
with a land vehicle. None of my deliveries would get to where they need 
to get to because of the limited cargo space of four wheeled vehicles. 
It would be just awful. Instead ...

class Land < Vehicle
  def initialize(a_hash) # lets initialize
    super # this loads in the other initialize stuff
    @num_wheels = a_hash[:num_wheels]
  end
end

dump_truck = Land.new(:weight => "30000",
                      :length => "28",
                      :height => "13.2",
                      :width => "9",
                      :num_wheels => "10")

Now that's a truck that'll hall a load of dirt away from my build site!

-- 
Posted via http://www.ruby-forum.com/.

0
greg5000 (10)
10/13/2009 5:17:10 AM
Reply: