Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.8 kB
5
Indexable
Never
fun main(args: Array<String>) {

    //car type
    var carType = arrayListOf<String>()
    //model
    var model = arrayListOf<String>()
    //year
    var year = arrayListOf<Int>()
    //price
    var price = arrayListOf<Double>()
    //km
    var kilometer = arrayListOf<Int>()
    //vin
    val vin = hashMapOf<Int, String>()
    var flag = "y"
    while (flag == "y") {

        println("1 regestr car ")
        println("2-  print car")
        println("3-  print car based on price ")
        println("4-  print cars based on KM ")
        println("5-  Apply Discount")
        println("6-  print car count ")
        println("7-  print all car price ")
        println("8-  print cars based on Model  ")
        println("9-  Search cars by Cars Type ")
        println("10- Search cars By car VIN ")
        
        println("please choose one: ")
        when (readLine()!!.toInt()) {
            1 -> {
                print("Register new car : ")

                var num: Int = 1
                println("Please Enter Car Info: or C to Cancel ")
                var i: Int = 0

                while (num >= 1) {
                    print("Enter car ${i + 1} Name : ")

                    var exp = Regex("\\w{3,50}")
                    var Carty = readLine()!!
                    if (Carty != "c") {
                    if (!exp.matches(Carty.toString())) {
                        println("Invalid car Type")
                        continue
                    }



                 

                        carType.add(Carty)

                        print("Enter car ${i + 1} Model : ")
                        model.add(readLine()!!)

                        print("Enter car ${i + 1} year : ")
                        var exp = Regex("\\d{4}")
                        var yearR = readLine()!!

                        if (!exp.matches(yearR.toString())) {


                            println("Invalid car year")
                            carType[i] = null.toString()
                            model[i] = null.toString()

                            continue
                        }
                        year.add(yearR.toInt())


                        print("Enter car ${i + 1} price : ")
                        price.add(readLine()!!.toDouble())


                        print("Enter car ${i + 1} KM's : ")
                        kilometer.add(readLine()!!.toInt())

                        print("Enter car ${i + 1} VIN  : ")
                        var tmpVin = readLine()!!.toString()
                        vin.put(i + 1, tmpVin)
                        i++
                        println("Please Enter Car ${i + 1} Info: or C to Cancel ")


                    } else
                        break

                }
            }
            2 -> {
                println("print All cars")
                if (!(carType.isNotEmpty())) {
                    print("No Cars Available !!")
                    break
                }
                //car type

                //model

                //year

                //price

                //km

                //vin
                for (i in 0 until carType.count()) {
                    println(
                        " car Type : ${carType[i]}  model : ${model[i]}  year : ${year[i]}  price : ${price[i]} " +
                                " kilometers : ${kilometer[i]} vin : ${vin.get(i)} SAR"
                    )
                }
            }
            else -> {
                print("do you want to continue ? y , n : ")
                flag = readLine()!!.toString()
            }
        }
    }
}