title | type | creator | competencies | ||||
---|---|---|---|---|---|---|---|
Method Madness |
homework |
|
Java, Methods |
Practice writing methods that return data and are void!
- Fork this repository
- Clone it to your computer
- Open the project in IntelliJ
- Create a new
src
directory and create aMadness.java
class inside of the project.
Inside of your Madness.java
, you'll need to write various methods. These methods should be defined inside of your Madness
class below your main
method. Some of these will return data; some may not. Complete as many as you can until your eyes bleed and then push your changes (sync/publish/push) and then create a pull request to submit your homework.
Hint You may need to research the
Math
class for help with this assignment.
- Define a function
maxOfTwoNumbers
that takes two numbers as arguments and returns the largest of them. I would suggest using conditional statements. Do some Googling to figure this out if you forget how conditionals work. - Define a function
maxOfThree
that takes three numbers as arguments and returns the largest of them. - Write a function
isCharacterAVowel
that takes a character (i.e. a string of length 1) and returns true if it is a vowel, false otherwise. - Write a function that return the number of arguments passed to the function when called.
- Define a function
reverseString
that computes the reversal of a string. For example, reverseString("jag testar") should return the string "ratset gaj". - Write a function
findLongestWord
that takes an array of words and returns the length of the longest one. - Write a function
filterLongWords
that takes an array of words and a numberi
and returns the array of words that are longer than i characters long. - Create a class, Car, that has the following member variables: mTopSpeed and mNumberOfDoors. In that class, write a constructor method that assigns random values to the member variables. Also, write a method that prints out the line "Your car has the top speed of ___ mph, and for some reason has ____ doors."
These are stretch goals; if you have time you should work on them! They are bonus.
- Write a function that takes in a number and returns true if the number is even or false if the number is odd. You may use control flow and multiple conditionals.
- Write a function that takes in two words and compares them. If the spelling is the same, the functions returns true, otherwise false.
- Write a function that takes in a word and prints out its every letter on a new line before it sees the letter "w". If it encounters "w" the function should stop executing.
- Write a function that generates a random number. Print it out. If the number is greater that 50, return it, otherwise return -1. You may use control flow and multiple conditionals.
- Write a function that takes in 3 integers: day, month, and year and computes day, month, and year of the next day. The function should return a string (e.g. day:12 month:11 year:1988)
- Write a function that takes in a word, omits every other letter in that word and returns a new word. You can use control flow and multiple conditionals.
- Write a function that takes in a number greater than 5 and prints out all the numbers from 1 to that number except number 4. Please use a while statement.
- Write a function that takes in 2 numbers, and checks if they are the same. If they are not the same, it adds 1 to every number and returns its sum. If the numbers are the same, it adds 2 to every number and returns its sum.
- Write a function that asks the user to enter a country domain. If the user types in "us", the function prints out "United States", if the user enters "de", the function prints out "Germany", if the user types in "hu" the response should be "Hungary". In all other cases the function should print out "Unknown". Please try to use a switch statement and make sure the function works with a user's input of lower and upper case strings.
- Write a function that asks the user to type in a letter and prints out whether the letter is a vowel or a consonant. You may use control flow and multiple conditionals.