Abdulmumin

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.7 kB
2
Indexable
Never
fun main() {

    print("Enter Numbers of Car: ")
    var carNum = 1
    var carModel = arrayListOf<String>()
    var carMod = " "
    var carYearArray = arrayListOf<Int>()
    var carYear = 0
    var carPriceArray = arrayListOf<Int>()
    var carPrice = 0
    var carKmArray = arrayListOf<Int>()
    var carKm = -1
    var sum = 0
    var counter = 0

    val year = Regex("\\d{0,4}")
    while (carNum != 0 ) {
        println("Enter the name of the car: ")
        carMod = readLine()!!.toString()
        carModel.add(carMod)


        println("Enter the year of the car: ")
        while (year.matches(carYear.toString()) == false) {
            carYear = readLine()!!.toInt()

            if (!year.matches(carYear.toString())){
                println("enter a correct year number !!")
                counter++
                if (counter>2) println("You should enter the 4 numbers")
            }

        }
        carYearArray.add(carYear)

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



            var km = Regex("\\d{0,9}")
      var r = 0
            println("Enter the KM of the car: ")
            while (km.matches(carKm.toString()) == false) {
                carKm = readLine()!!.toInt()
                if (!km.matches(carKm.toString())){
                    println("enter a correct year number !!")
                    r++
                    if (r>2) println("You should enter numbers")
                }

            }

        carKmArray.add(carKm)
        }


    var k = 1
    var stop='r'
    do {
        var option = readLine()!!.toInt()
        when (option) {
            1 -> for (i in 0 until carModel.size) {
                println("the full data of the Car no: $k\n" + carModel[i] + " " + carYearArray[i] + " " + carPriceArray[i] + " " + carKmArray[i] + " " + "\n")
                println("-----------------------------")
                k++
            }
            2 -> {
                println("enter a range of salaries: ")
                var from = readLine()!!.toInt()
                var to = readLine()!!.toInt()
                for (i in 0 until carKmArray.size)
                    if (carPriceArray[i] in from..to) println( carModel[i] + " " + carYearArray[i] + " " + carPriceArray[i] + " " + carKmArray[i])
            }
            
            else -> println("ENTER A CORRECT NUMBER !\nOR N to STOP")
        }
        println("do you want to make another enquiry ?\nY/N")
        stop= readLine()!!.single()


    } while (stop == 'Y' || stop=='y')
    }