type Car struct {
battery int
batteryDrain int
speed int
distance int
}
// NewCar creates a new remote controlled car with full battery and given specifications.
func NewCar(speed, batteryDrain int) Car {
return Car{
battery: 100,
batteryDrain: batteryDrain,
speed: speed,
distance: 0,
}
}
If you use codeblocks, the code is much easier to read.
You should run the tests. The tests will tell you what’s wrong. If you’d like help interpreting the test output, please share the test output (using a codeblock and not a screenshot).
This was the initial code that was given to you: did you delete it?
package speed
// TODO: define the 'Car' type struct
// NewCar creates a new remote controlled car with full battery and given specifications.
func NewCar(speed, batteryDrain int) Car {
panic("Please implement the NewCar function")
}
// TODO: define the 'Track' type struct
// NewTrack creates a new track
func NewTrack(distance int) Track {
panic("Please implement the NewTrack function")
}
// Drive drives the car one time. If there is not enough battery to drive one more time,
// the car will not move.
func Drive(car Car) Car {
panic("Please implement the Drive function")
}
// CanFinish checks if a car is able to finish a certain track.
func CanFinish(car Car, track Track) bool {
panic("Please implement the CanFinish function")
}
Remember to read the entire exercise and the comments, and if you are ever left wondering why there are so many errors, check how the tests are written and what they are requiring to be executed, the test says it all, you need the Track, but surely now you did it. I always recommend you review this before, it can be of great help and you will learn the importance of the tests!