Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object Day01 extends App{
- println("Age Till 65 Method")
- println("===========================================")
- ageTillSixtyFive("Cooper", 19)
- ageTillSixtyFive("Cooper", 65)
- ageTillSixtyFive("Cooper", 95)
- //////////////////////////////////////////////////
- println()
- println()
- println()
- ////////////////////////////////////////////////////
- println("Find Max Method")
- println("===========================================")
- println(findMax(7, 10))
- println(findMax(9399, 4383))
- println(findMax(1, 100))
- //////////////////////////////////////////////////
- println()
- println()
- println()
- ////////////////////////////////////////////////////
- println("Summer Winter Method")
- println("===========================================")
- println(summer_winter(15))
- println(summer_winter(33))
- println(summer_winter(97))
- println(summer_winter(100))
- //////////////////////////////////////////////////
- println()
- println()
- println()
- ////////////////////////////////////////////////////
- println("Check Speed Method")
- println("===========================================")
- checkSpeed(45)
- checkSpeed(60)
- checkSpeed(90)
- checkSpeed(119)
- checkSpeed(120)
- //////////////////////////////////////////////////
- println()
- println()
- println()
- ////////////////////////////////////////////////////
- println("Odd Even Method")
- println("===========================================")
- oddEven(10)
- //////////////////////////////////////////////////
- println()
- println()
- println()
- ////////////////////////////////////////////////////
- println("Sum of 3's and 5's Method")
- println("===========================================")
- println(sumOfThreesAndFives(20))
- println(sumOfThreesAndFives(28))
- println(sumOfThreesAndFives(96))
- //////////////////////////////////////////////////
- println()
- println()
- println()
- ////////////////////////////////////////////////////
- println("isPrime Method")
- println("===========================================")
- println(isPrime(7))
- println(isPrime(49))
- println(isPrime(97))
- //////////////////////////////////////////////////
- println()
- println()
- println()
- ////////////////////////////////////////////////////
- println("printPrimes Method")
- println("===========================================")
- printPrimes(100)
- //////////////////////////////////////////////////
- println()
- println()
- println()
- ////////////////////////////////////////////////////
- println("printPrimes Method")
- println("===========================================")
- sort(1,2,3)
- sort(1,3,2)
- sort(2,1,3)
- sort(2,3,1)
- sort(3,2,1)
- sort(3,1,2)
- //////////////////////////////////////////////////
- println()
- println()
- println()
- ////////////////////////////////////////////////////
- println("isPerfectNumber Method")
- println("===========================================")
- println(isPerfectNumber(28))
- // #1
- def ageTillSixtyFive(name: String, age: Int): Unit = {
- val currentYear = 2019
- println(s"Hello $name you will turn 65 in ${65 - age + currentYear}")
- }
- // #2
- def findMax(numberOne: Int, numberTwo: Int): Int = {
- if (numberOne > numberTwo) numberOne
- else numberTwo
- }
- // #3
- def summer_winter(number: Int): String = {
- if (number % 3 == 0 && number % 5 == 0) "SummerWinter"
- else if (number % 3 == 0) "Summer"
- else if (number % 5 == 0) "Winter"
- else number.toString
- }
- // #4
- def checkSpeed(speed: Int): Unit = {
- var points: Int = 0
- if (speed < 55) println("Ok")
- else {
- points = (speed - 55) / 5
- println(s"Points: $points")
- }
- if (points > 12) println("License Suspended")
- }
- // #5
- def oddEven(limit: Int): Unit = {
- var postFix = ""
- for(i <- 0 to limit) {
- if (i % 2 == 0) postFix = "Even"
- else postFix = "Odd"
- println(s"$i is $postFix")
- }
- }
- // #6
- def sumOfThreesAndFives(limit: Int): Int = {
- var sum = 0
- for (i <- 0 to limit) {
- if (i % 3 == 0 || i % 5 == 0) sum += i
- }
- sum
- }
- // #7
- def isPrime(number: Int): Boolean = {
- /* Logic = Start at 2 and proceed to half the number
- Ex.) isPrime(40)
- for loop ranges from 2 to 20
- if 40 % 2 == 0 then 40 is not prime
- if this failed the first time, say the number is now 30
- we proceed to the next number to search for a divisor that is not 1 nor the number itself.
- */
- var initialBool = true
- for (i <- 2 to (number / 2)) {
- if (number % i == 0) initialBool = false
- }
- initialBool
- }
- // #8
- def printPrimes(limit: Int): Unit = {
- for (i <- 0 to limit) {
- if (i > 1) {
- if (isPrime(i)) println(i)
- }
- }
- }
- // #9
- def sort(x: Int, y: Int, z: Int): Unit = {
- if (x > y && x > z && y > z) print(x,y,z)
- if (x > y && x > z && z > y) print(x,z,y)
- if (y > x && y > z && x > z) print(y,x,z)
- if (y > x && y > z && z > x) print(y,z,x)
- if (z > y && z > x && x > y) print(z,x,y)
- if (z > y && z > x && y > x) print(z,y,x)
- println()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement