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

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/

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.

Walton H. 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?

Ghost Alpha wrote:

Walton H. 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!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs