Last active
December 12, 2018 16:50
-
-
Save adolfont/57e901ead4648c4ffa65ea80b27f8f78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Run in shell with | |
| # elixir university.exs | |
| defmodule University do | |
| def average(p1, p2), do: (p1 + p2) / 2 | |
| def average(p1, p2, p3), do: (p1 + p2 + p3) / 3 | |
| defp professor_base_salary(:adjunct, "US$"), do: 20000 | |
| defp professor_base_salary(:adjunct, "R$"), do: 30000 | |
| defp professor_base_salary(:assistant, currency), | |
| do: 3 * professor_base_salary(:adjunct, currency) | |
| defp professor_base_salary(:associate, currency), | |
| do: 5 * professor_base_salary(:adjunct, currency) | |
| defp professor_base_salary(:full, currency), do: 10 * professor_base_salary(:adjunct, currency) | |
| def professor_annual_salary(name, position, currency) do | |
| {name, professor_base_salary(position, currency), currency} | |
| end | |
| def main() do | |
| IO.puts("Salaries at the University of Some Place (USP)\n") | |
| {name, salary, currency} = professor_annual_salary("John", :full, "US$") | |
| IO.puts("#{name} receives an annual salary of #{currency} #{salary}\n") | |
| {name, salary, currency} = professor_annual_salary("João", :associate, "R$") | |
| IO.puts("#{name} receives an annual salary of #{currency} #{salary}\n") | |
| end | |
| end | |
| University.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment