Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def passwordValid(): Boolean = {
- println("Write your password: ")
- val input = scala.io.StdIn.readLine()
- val alphabetLower = ('a' to 'z').toList
- println(alphabetLower)
- val alphabetUpper = ('A' to 'Z').toList
- val numbers = ('0' to '9').toList
- val symbols = List('$', '#', '@')
- val mergedList = alphabetLower:::alphabetUpper:::numbers:::symbols
- println(mergedList)
- var lowerCount = 0
- var upperCount = 0
- var numberCount = 0
- var characterCount = 0
- val minLength = 6
- val maxLength = 16
- var condition = true
- if (minLength <= input.length() && input.length() <= maxLength) {
- for (i <- input.toCharArray) {
- if (!mergedList.contains(i.toChar)) {
- println(i)
- condition = false
- } else {
- if (alphabetLower.contains(i)) {
- lowerCount += 1
- }
- if (alphabetUpper.contains(i)) {
- upperCount += 1
- }
- if (numbers.contains(i)) {
- numberCount += 1
- }
- if (symbols.contains(i)) {
- characterCount += 1
- }
- }
- }
- }
- if (!(lowerCount > 0 && upperCount > 0 && numberCount > 0 && characterCount > 0 )) {
- condition = false
- }
- println(condition)
- condition
- }
- def numberToAverage(number: Int): Unit = {
- if (number > 1) {
- println(s"Average is ${number/2} and the number is $number")
- } else {
- println("Please use a number greater than 1 next time")
- }
- }
- def printEven(limit: Int): Unit = {
- for (i <- 0 to limit)
- if (i % 2 == 0) {
- println(i)
- }
- }
- def getNextDay():Unit = {
- 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)
- println("Enter a year:")
- val year = scala.io.StdIn.readLine()
- println("Enter a month:")
- val month = scala.io.StdIn.readLine()
- println("Enter a day:")
- val day = scala.io.StdIn.readLine()
- try {
- var yearInt = year.toInt
- var monthInt = month.toInt
- var dayInt = day.toInt
- if (yearList.contains(monthInt)) {
- // if we are on the last day of the month cycle to next month and begin day 1
- if (dayInt == yearList(monthInt)) {
- // if we are on the last day of december increase the year and go to Jan 1st
- if (monthInt == 12) {
- yearInt += 1
- monthInt = 1
- dayInt = 1
- }
- else {
- monthInt += 1
- dayInt = 1
- }
- } else {
- dayInt += 1
- }
- println(s"Year: $yearInt, Month: $monthInt, Day: $dayInt")
- } else {
- println("Your month number is invalid. Please chose a number from 1-12")
- }
- } catch {
- case e: NumberFormatException => None
- println("Please enter only numbers next time")
- }
- }
- def uniqueValueFinder(dict: Map[Int, Int]): Int = {
- dict.values.toSet.toList.length
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement