Need Help with this problem

G

Ghost Alpha

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
 
G

Ghost Alpha

Ghost said:
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/
 
W

Walton Hoops

Ghost said:
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.
 
G

Ghost Alpha

Walton said:
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?
 
G

Greg Barozzi

Ghost said:
Walton said:
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,166
Messages
2,570,907
Members
47,446
Latest member
Pycoder

Latest Threads

Top