I am a first-year CS student, and not one of them knew about programming. We have just finished our time with functional programming and are now moving on to object-oriented programming. I am currently working on a task in which I must imitate the race between animals. These animals were given some attributes and methods that determine their weight, maximum speed, etc. One of the requirements of the code is that it must generate a random variable that determines its weight for each instance it invokes. So far I have come to this point in my code:
let rnd = System.Random()
type Animal (name:string, animalWeight:float, maxSpeed:float) = class
let mutable foodInTakePercentage = float(rnd.Next(0,101))
member val animalMaxSpeed : float = maxSpeed with get, set
member val animalWeight = animalWeight with get, set
member val neccesaryFoodIntake = 0.0 with get, set
member val Name = name
new (name, maxSpeed) =
let minWeight = 70.0
let maxWeight = 300.0
let Weight = minWeight + rnd.NextDouble() * (maxWeight-minWeight)
Animal (name, Weight, maxSpeed)
member this.FoodInTakePercentage = foodInTakePercentage/100.0
member this.CurrentSpeed =
this.FoodInTakePercentage*maxSpeed
abstract FoodIntake : float
default this.FoodIntake = 0.5
member this.NeccesaryFoodIntake =
neccesaryFoodIntake <- animalWeight * FoodIntake
end
type Carnivore (name:string, animalWeight:float, maxSpeed:float) = class
inherit Animal (name, animalWeight, maxSpeed)
override this.FoodIntake = 0.08
end
type Herbivore (name:string, animalWeight:float, maxSpeed:float) = class
inherit Animal (name, animalWeight, maxSpeed)
override this.FoodIntake = 0.4
end
The problem is that when compiling I get an error:
10g.fsx(22,5): error FS0039: The value or constructor 'neccesaryFoodIntake' is not defined
( ), , . - ?