Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.87 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. const usixteenbitmax float64 = 65535
  6. const kmh_multiple float64 = 1.60934
  7.  
  8. type car struct {
  9.     gas_pedal      uint16 //min 0 max 65535
  10.     brake_pedal    uint16
  11.     steering_wheel int16 // -32k - +32k
  12.     top_speed_kmh  float64
  13. }
  14.  
  15. func (c car) kmh() float64 {
  16.     return float64(c.gas_pedal) * (c.top_speed_kmh / usixteenbitmax)
  17. }
  18.  
  19. func (c *car) mph() float64 {
  20.     c.top_speed_kmh = 500
  21.     return float64(c.gas_pedal) * (c.top_speed_kmh / usixteenbitmax / kmh_multiple)
  22. }
  23.  
  24. func (c *car) new_top_speed(newspeed float64) {
  25.     c.top_speed_kmh = newspeed
  26. }
  27.  
  28. func main() {
  29.     a_car := car{
  30.         gas_pedal:      24000,
  31.         brake_pedal:    0,
  32.         steering_wheel: 12561,
  33.         top_speed_kmh:  225.0}
  34.  
  35.     fmt.Println(a_car.brake_pedal)
  36.     fmt.Println(a_car.kmh())
  37.     fmt.Println(a_car.mph())
  38.     a_car.new_top_speed(500)
  39.     fmt.Println(a_car.kmh())
  40.     fmt.Println(a_car.mph())
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement