In this project, you will write some basic functions in Go. The goal here is to speedrun an intro programming course (sans objects). Please look to the submission instructions at the bottom to see some of the details of the file you will be submitting. Reminder, you can test code in Go in a browser at The Go Playground.
Part 0, 1 points: Write a function, SumTwo
, from class, that takes two int parameters and returns the sum.
Part 1, 15 points: Write a function, FahrenheitToCelsius
, that takes a float (float64
) parameter as the degrees Fahrenheit and returns the same temperature, but in degrees Celsius.
Part 2, 10 points: Conditionals! Write your favorite function, CarpetFootage
, in Go. It should take two integers and return an integer. (Reminder: the width of a carpet roll is 12 feet.)
Part 3, 1 points: Recursion! Write your favorite recursive function, Factorial
, in Go. It should take one integer, n, and return n!.
Part 4, 20 points: Write a primality-checking function, IsPrime
, in Go. It should take one integer, n, and return whether n is prime.
Part 5, 1 points: Loops! Use a for loop to write PrintMonkeys
, in Go. It should take one integer, n, and print "monkey" n times in a line with a space between each one. E.g.: PrintMonkeys(5)
should print out:monkey monkey monkey monkey monkey
Part 6, 10 points: Write PrintNumbers
, in Go. It should take one integer, n, and prints lines with integers starting with 1 and going up to 1 2 3 ... n. E.g.: PrintNumbers(5)
should print out:1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Part 7, 10 points: Instead of string methods, Go uses the strings package to do those operations. Write SmallestMissingDigit
, in Go. It should take a string, and return the smallest integer, 0 through 9, that isn't in the string. If all ten digits are in the string, it should return -1. E.g.: SmallestMissingDigit("Got 0, 1, and 2.")
should return 3.
Part 8, 1 points: Write HasMonkey
, in Go. It should take an array of strings and return whether or not array contains "monkey".
Part 9, 10 points: Write GetOnes
, in Go. It should take one integer, n, and return an array with n ones. E.g.: GetOnes(5)
should return an array with exactly five 1s and no other elements.
Part 10, 10 points: Create a new struct for Pokemon with five fields: - name, a string
- number, an int
- types, an array of strings
- hitPoints, an int, and
- maxHP, another int.
, then add a NewPokemon
function to act as a constructor. It should take four parameters: a string (for the name), an integer (for the number), an array of strings (for the types), and another integer (for the hitPoints and maxHP).
Part 11, 1 points: Write the GetName
method for Pokemon, which returns the name of the pokemon subject.
Part 12, 10 points: Write the SprayPotion
method for Pokemon, which, if the subject Pokemon is not fainted, increases its hit points by 20 (but it can't go above the max).
Submitting your Project: Put all your code in one file named project9.go
in a folder named <TeamName>Project9, where <TeamName> has all team members' (last) names separated by 'And' in PascalCase. For example, if I had worked with Eve Stock, my folder name would be BurkeAndStockProject9. The code file should be located directly in that folder. Since Go is a compiled language, if you want me to grade it before you're done, add stub functions for all the unfinished parts so it can compile with my testing code. Make sure your file does not have a main
function! Zip the folder up (don't change the name of the zipped file) and upload the zip file to the assignment in Canvas.