Rakan

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

    var Ncar = arrayListOf<String>()
    var Mcar = arrayListOf<String>()
    var Pcar = arrayListOf<Int>()
    var Kcar = arrayListOf<Int>()

    var x = 1
    var Car = 0
    var count = 0
    var prices = 0

    var Model = Regex("([0-9]{4})")

    var Type_car = Regex("([a-zA-Z]{1,20})")
    while (x != 0) {

        print("enter the name of car :")
        var car = readLine()!!.toString()

        Ncar.add(car)
        print("enter the car model: ")
        Mcar.add(readLine()!!)

    }
    print("enter the car  year: ")
    var yar = readLine()!!.toString()
    while (!Model.matches(yar)) {

    }


    print("enter car  price: ")
    Pcar.add(readLine()!!.toInt())
    prices += Pcar[Car]

    print("how mny kilo? ")
    var kilo = readLine()!!.toInt()
    Kcar.add(kilo)
    var option = 1
    while (option != 0) {
        println(
            "please choose: \n1- print all car\n2-search name car\n" +
                    "3- print cars by price range\n4- print car by kilo\n5-make discount\n" +
                    "6- print how many car in plice\n7-Print total prices car \n8- to print car model" +
                    "\n0 to exit"
        )
        var check = readLine()!!.toInt()
        when (check) {

            0 -> option = 0

            1 -> for (i in 0 until Ncar.size) {
                println("Car name:" + Ncar[i] + "\nCar model: " + Mcar[i] + "\nMade year: " +  "\nPrice: " + Pcar[i] + "\n kiloe: " + Kcar[i] + "\n")
            }
            2 -> {
                println("enter the car that you want to search:")
                var temp_car = readLine()!!.toString()
                for (i in 0 until Ncar.size)
                    if (temp_car.equals(Ncar[i]))
                        println("Car name:" + Ncar[i] + "\nCar model: " + Mcar[i] + "\nMade year: " +  "\nPrice: " + Pcar[i] + "\n kiloe: " + Kcar[i] + "\n")
            }
            3 -> {
                println(" enter the low price: ")
                var low = readLine()!!.toInt()
                println("enter the high price: ")
                var high = readLine()!!.toInt()
                for (i in 0 until Ncar.size) {
                    if (low <= Pcar[i] && high >= Pcar[i])
                        println("Car name:" + Ncar[i] + "\nCar model: " + Mcar[i] + "\nMade year: " + "\nPrice: " + Pcar[i] + "\n kiloe: " + Kcar[i] + "\n")
                }
            }
            4 -> {
                println("enter the low Kilo: ")
                var lowkilo = readLine()!!.toInt()
                println(" enter the high Kilo: ")
                var highkilo = readLine()!!.toInt()
                for (i in 0 until Ncar.size)
                    if (Kcar[i] in lowkilo..highkilo)
                        println("Car name:" + Ncar[i] + "\nCar model: " + Mcar[i] + "\nMade year: " +  "\nPrice: " + Pcar[i] + "\n kiloe: " + Kcar[i] + "\n")
            }

            5 -> {
                println("enter the discount: ")
                var dcount = readLine()!!.toInt()
                for (i in 0 until Ncar.size) {
                    println(
                        "Car name: " + Ncar[i] + "\nCar model: " + Mcar[i] + "\nMade year: " + "\n" + "Price before discount: " + Pcar[i] + "\n" +
                                "Price after discount: " + (Pcar[i] * dcount / 100 - Pcar[i]) + "\n kiloe: " + Kcar[i] + "\n"
                    )
                }

            }

            6 -> println("Total cars in show room: " + count + "\n")

            7 -> println("Total prices all cars: " + prices + "\n")

            8 -> {
                println("enter the model: ")
                var temp = readLine()!!
                for (i in 0 until Ncar.size)
                    if (temp == Mcar[i])
                        println("Car name:" + Ncar[i] + "\nCar model: " + Mcar[i] + "\nMade year: " +  "\nPrice: " + Pcar[i] + "\n kiloe: " + Kcar[i] + "\n")
            }


        }
    }
}