Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- note
- description: "Temperature."
- class
- TEMPERATURE
- create
- make_celsius, make_kelvin
- feature — Initialization
- make_celsius (v: INTEGER)
- — Create with Celsius value `v'.
- require
- temperature_valid: v >= -273
- do
- — Create a temperature object encapsulating value 'v' intended in Celsius.
- — Your code here
- celsius := v
- ensure
- celsius_set: celsius = v
- end
- make_kelvin (v: INTEGER)
- — Create with Kelvin value `v'.
- require
- temperature_valid: v >= 0
- do
- — Your code here
- — Create a temperature object encapsulating value 'v' intended in Kelvin.
- celsius := v - 273
- ensure
- celsius_set: celsius = v - 273
- kelvin_set: kelvin = v
- end
- feature — Access
- celsius: INTEGER
- — Value in Celsius scale.
- kelvin: INTEGER
- — Value in Kelvin scale.
- do
- — Your code here
- — Compute the Kelvin temperature value from the Celsius value
- Result := celsius + 273
- end
- feature — Measurement
- average (other: TEMPERATURE): TEMPERATURE
- — Average temperature between `Current' and `other'.
- require
- valid_temperature_object: other /= Void
- do
- — Your code here.
- — Compute the average of two temperature. One is given by the current object,
- — the other is passed as an argument.
- create Result.make_celsius ((Current.celsius + other.celsius) // 2)
- ensure
- (Result.celsius >= other.celsius and Result.celsius <= Current.celsius) or (Result.celsius >= Current.celsius and Result.celsius <= other.celsius)
- end
- invariant
- never_below_zero: kelvin >= 0
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement