Creating your first method

Report a typo

Below you will see a Go program with the Employee struct type declaration. The program takes as input the FirstName, LastName, and Salary (in USD) of the Employee.

Please create the GetSalary() method for the Employee type that returns the Salary; then call and print the GetSalary() method in the main function within the fmt.Printf(...) statement where the ? sign is.

The output of the program should look like this:

Homer Simpson earns: 💲 362.19 USD

Sample Input 1:

Homer Simpson 362.19

Sample Output 1:

Homer Simpson earns: 💲 362.19 USD
Write a program in Go
package main

import "fmt"

type Employee struct {
FirstName, LastName string
Salary float64
}

// Create the GetSalary() method below for the 'Employee' type that returns the 'Salary' field.
func (? ?) ? float64 {
return ?
}

func main() {
// Do not change the code below!
var e Employee
fmt.Scanln(&e.FirstName, &e.LastName, &e.Salary)

// call the GetSalary() method on the '?' sign!
fmt.Printf("%s %s earns: 💲 %.2f USD\n", e.FirstName, e.LastName, ?)
}
___

Create a free account to access the full topic