Abdulmumin

 avatar
unknown
plain_text
2 years ago
2.5 kB
2
Indexable
fun main() {
    var carModel = arrayListOf<String>()
    var carMod = ""

    var carYearArr = arrayListOf<Int>()
    var carYear = 0

    var carPrice = arrayListOf<Double>()
    var carP = 0.0

    var carKmAr = arrayListOf<Int>()
    var carKm = 0


    var year = Regex("\\d{4}")
    var kil = Regex("\\d{0,9}")
    var name = Regex("A-Za-Z")
    var carNum = -1
    var loop = 0
    var stop = 1
    while (carNum != 0) {

        println("Enter the model of the Car: ")
        carMod = readLine()!!
        while (!name.matches(carMod)== false) {
            println("Enter a correct model number !!")
            carMod = readLine()!!
        }
        carModel.add(carMod)

        println("Enter the year of the car: ")
        carYear = readLine()!!.toInt()
        while (!year.matches(carYear.toString())) {
            println("Enter a correct year number !!")
            carYear = readLine()!!.toInt()
        }
        carYearArr.add(carYear)

        println("Enter the price of the car: ")
        carP = readLine()!!.toDouble()
        carPrice.add(carP)

        println("Enter the kilo of the car: ")
        carKm = readLine()!!.toInt()
        while (!kil.matches(carKm.toString())) {
            println("Enter a correct kilo number !!")
            carKm = readLine()!!.toInt()
        }
        carKmAr.add(carKm)
        loop++
        println("To stop = 0 ")
        stop = readLine()!!.toInt()
        if (stop == 0) {
           carNum = 0
        }
    }
    var x = -1
    while (x != 0) {
        println(
                "choose from the following:\n " +
                        "1- to print out the full data of cars\n " +
                        "2-to print out a cars price \n" +
                        "3-to print out a list of the kilometer\n" +
                        "4-to print out a number of cars\n " +


                        "Any else number out !!")
        x = readLine()!!.toInt()
        when (x) {
            1 -> {
                for (i in carModel.indices) {
                    println(carModel[i] + " -- " + carYearArr[i] + " -- " + carPrice[i] + " -- " + carKmAr[i]+"\n")
                }

            }
            2 -> {
            for (i in carModel.indices) {
                println(carModel[i] + " -- " + carYearArr[i] + " -- " + carPrice[i] + " -- " + carKmAr[i]+"\n")
            }
        }
            else -> {
                println("Out ..")
            }


        }
}
}
Editor is loading...