Threesuns

Email the Instructor

Contact

All Semesters

Semesters

All Courses

Courses

2014Fall

08.19.13 - 12.20.13

Ruby

CSYS2853

Tuesday Thursday
04:00 PM - 05:20 PM

Distance

Lab06

Objective: To practice working with classes and operators

pastdue

Submit Your Solution

Lab06

Request a Copy of your Solution

Lab06

Requirements

Distance class created10 pts
Distance class can store values as Miles or Kilometers10 pts
Addition can be performed correctly20 pts
Subtraction can be performed correctly20 pts
Multiplication can be performed correctly20 pts
Division can be performed correctly20 pts
Total100 pts

Instructions

Create a class called Distance whose objects can store a distance measured in either miles or kilometers. Set up your Distance class so its objects can be added, subtracted, multiplied, or divided by other distance objects.

When the two distance objects that are being worked with are not in the same units a conversion will have to take place. To convert miles to kilometers multiple the value by 1.60934 and to convert kilometers to miles multiple the value by 0.621371

Your distance class is correct when it can run the attached code and produce the following output:

Adding:
1.621371 Miles
4 Miles
4
m
6 Kilometers
10.43736 Kilometers
------------------------------
Subtracting:
0.378629 Miles
0 Miles
0
m
0 Kilometers
-2.43736 Kilometers
------------------------------
Multiplying:
0.621371 Miles
4 Miles
4
m
9 Kilometers
25.74944 Kilometers
------------------------------
Dividing:
1.6093444978925633 Miles
1 Miles
1
m
1 Kilometers
0.6213727366498067 Kilometers

Extras