Advertisement
Guest User

Untitled

a guest
Jul 11th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 3.05 KB | None | 0 0
  1. def passwordValid(): Boolean = {
  2.     println("Write your password: ")
  3.     val input = scala.io.StdIn.readLine()
  4.  
  5.     val alphabetLower = ('a' to 'z').toList
  6.     println(alphabetLower)
  7.     val alphabetUpper = ('A' to 'Z').toList
  8.     val numbers = ('0' to '9').toList
  9.     val symbols = List('$', '#', '@')
  10.     val mergedList = alphabetLower:::alphabetUpper:::numbers:::symbols
  11.     println(mergedList)
  12.  
  13.     var lowerCount = 0
  14.     var upperCount = 0
  15.     var numberCount = 0
  16.     var characterCount = 0
  17.     val minLength = 6
  18.     val maxLength = 16
  19.  
  20.     var condition = true
  21.  
  22.     if (minLength <= input.length() && input.length() <= maxLength) {
  23.       for (i <- input.toCharArray) {
  24.         if (!mergedList.contains(i.toChar)) {
  25.           println(i)
  26.           condition = false
  27.         } else {
  28.           if (alphabetLower.contains(i)) {
  29.             lowerCount += 1
  30.           }
  31.           if (alphabetUpper.contains(i)) {
  32.             upperCount += 1
  33.           }
  34.           if (numbers.contains(i)) {
  35.             numberCount += 1
  36.           }
  37.           if (symbols.contains(i)) {
  38.             characterCount += 1
  39.           }
  40.         }
  41.       }
  42.     }
  43.     if (!(lowerCount > 0 && upperCount > 0 && numberCount > 0 && characterCount > 0 )) {
  44.       condition = false
  45.     }
  46.     println(condition)
  47.     condition
  48.   }
  49.  
  50.  
  51.   def numberToAverage(number: Int): Unit = {
  52.     if (number > 1) {
  53.       println(s"Average is ${number/2} and the number is $number")
  54.     } else {
  55.       println("Please use a number greater than 1 next time")
  56.     }
  57.   }
  58.  
  59.  
  60.   def printEven(limit: Int): Unit = {
  61.     for (i <- 0 to limit)
  62.       if (i % 2 == 0) {
  63.         println(i)
  64.       }
  65.   }
  66.  
  67.   def getNextDay():Unit = {
  68.     val yearList = Map(1 -> 31, 2 -> 28, 3 -> 31, 4 -> 30, 5 -> 31, 6 -> 30, 7 -> 31, 8 -> 31, 9 -> 30, 10 -> 31, 11 -> 30, 12 -> 31)
  69.  
  70.     println("Enter a year:")
  71.     val year = scala.io.StdIn.readLine()
  72.  
  73.     println("Enter a month:")
  74.     val month = scala.io.StdIn.readLine()
  75.  
  76.     println("Enter a day:")
  77.     val day = scala.io.StdIn.readLine()
  78.  
  79.     try {
  80.       var yearInt = year.toInt
  81.       var monthInt = month.toInt
  82.       var dayInt = day.toInt
  83.  
  84.       if (yearList.contains(monthInt)) {
  85.         // if we are on the last day of the month cycle to next month and begin day 1
  86.         if (dayInt == yearList(monthInt)) {
  87.           // if we are on the last day of december increase the year and go to Jan 1st
  88.           if (monthInt == 12) {
  89.             yearInt += 1
  90.             monthInt = 1
  91.             dayInt = 1
  92.           }
  93.           else {
  94.             monthInt += 1
  95.             dayInt = 1
  96.           }
  97.         } else {
  98.           dayInt += 1
  99.         }
  100.         println(s"Year: $yearInt, Month: $monthInt, Day: $dayInt")
  101.       } else {
  102.         println("Your month number is invalid. Please chose a number from 1-12")
  103.       }
  104.  
  105.     } catch {
  106.       case e: NumberFormatException => None
  107.         println("Please enter only numbers next time")
  108.     }
  109.  
  110.   }
  111.  
  112.  
  113.   def uniqueValueFinder(dict: Map[Int, Int]): Int = {
  114.     dict.values.toSet.toList.length
  115.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement