Untitled

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

    var carType = arrayListOf<String>()
    var model = arrayListOf<String>()
    var manufacturingyear = arrayListOf<String>()
    var pric = arrayListOf<Int>()
    var kile = arrayListOf<Int>()
    var x = 1
    var carr = 0
    var count = 0
    var prices = 0
    var year_11 = Regex("([0-9]{4})")
    var manufacturingyear_re = Regex("([0-9]{0,4})")
    var typ_car = Regex("([a-zA-Z]{1,20})")
    while (x != 0) {

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


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

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

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

    print("how mny kilo? ")
    var kilo = readLine()!!.toInt()
    while (!manufacturingyear_re.matches(kilo.toString())) {
        print("enter correct kilo ")
        kilo = readLine()!!.toInt()
    }
    kile.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 carType.size) {
                println("Car name:" + carType[i] + "\nCar model: " + model[i] + "\nMade year: " + manufacturingyear[i] + "\nPrice: " + pric[i] + "\n kiloe: " + kile[i] + "\n")
            }
            2 -> {
                println("enter the car that you want to search:")
                var temp_car = readLine()!!.toString()
                for (i in 0 until carType.size)
                    if (temp_car.equals(carType[i]))
                        println("Car name:" + carType[i] + "\nCar model: " + model[i] + "\nMade year: " + manufacturingyear[i] + "\nPrice: " + pric[i] + "\n kiloe: " + kile[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 carType.size) {
                    if (low <= pric[i] && high >= pric[i])
                        println("Car name:" + carType[i] + "\nCar model: " + model[i] + "\nMade year: " + manufacturingyear[i] + "\nPrice: " + pric[i] + "\n kiloe: " + kile[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 carType.size)
                    if (kile[i] in lowkilo..highkilo)
                        println("Car name:" + carType[i] + "\nCar model: " + model[i] + "\nMade year: " + manufacturingyear[i] + "\nPrice: " + pric[i] + "\n kiloe: " + kile[i] + "\n")
            }

            5 -> {
                println("enter the discount: ")
                var dcount = readLine()!!.toInt()
                for (i in 0 until carType.size) {
                    println(
                        "Car name: " + carType[i] + "\nCar model: " + model[i] + "\nMade year: " + manufacturingyear[i] + "\n" + "Price before discount: " + pric[i] + "\n" +
                                "Price after discount: " + (pric[i] * dcount / 100 - pric[i]) + "\n kiloe: " + kile[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 carType.size)
                    if (temp == model[i])
                        println("Car name:" + carType[i] + "\nCar model: " + model[i] + "\nMade year: " + manufacturingyear[i] + "\nPrice: " + pric[i] + "\n kiloe: " + kile[i] + "\n")
            }


        }
    }
}