/ scala

Scala 004 Random Name Generator

Very rough code

Names are limited to those in the arrays.

Solution

nameGenerator.scala

object nameGenerator {
  def main(args: Array[String]){
    var maleNames = Array("Aadam", "Aadi", "Aahil", "Adam", "Harry", "Oliver", "Jack", "Charlie", "Alfie", "Thomas", "James", "Jacob", "Joshua", "William")
    var femaleNames = Array("Amelia", "Olivia", "Lily", "Jessica", "Emily", "Sophie", "Grace", "Ruby", "Ava", "Isabella", "Sue", "Paige", "Jasmine", "Molly")
    var input = ""
    val r = new scala.util.Random
    while (input != "q") {
      input = readLine ("\nMale or Female?\n---------------\n(f/m)> ")
      if (input == "m") {
        println(maleNames(r.nextInt(maleNames.length)))
      }
      else if (input == "f") {
        println(femaleNames(r.nextInt(femaleNames.length)))
      }
      else {
        println("\nPlease enter valid reply")
      }
    }
  }