Untitled

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

    var carType = arrayListOf<String>()
    var model = arrayListOf<String>()
    var manifacturingyear = arrayListOf<String>()
    var pric = arrayListOf<Int>()
    var km = arrayListOf<Int>()
    var x = 1
    var carr = 0
    var count = 0
    var prices = 0
    var year = Regex("([0-9]{4})")
    var manifacturingyear_re = Regex("([0-9]{0,4})")
    var typ_car = Regex("([a-zA-Z]{1,20})")

    while (x != 0) {

        print("Enter The Car Name :")
        var car = readLine()!!.toString()


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

        print("enter the car  year: ")
        var yar = readLine()!!.toString()

        while (!year.matches(yar)) {
            print("enter  correct year : ")
            yar = readLine()!!.toString()
        }
        manifacturingyear.add(yar)

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



        print("how many km? ")
        var kilo = readLine()!!.toInt()
        while (!manifacturingyear_re.matches(kilo.toString())) {
            print("enter correct kilo ")
            kilo = readLine()!!.toInt()
        }
        km.add(kilo)



        carType.add(car)


        print("enter 1 to add cars or 0 to quit: ")
        x = readLine()!!.toInt()

    }






    var option = 1
    while (option != 0) {
        println(
            """please choose: 
1- print all car
2- search name car
3- print cars by price range
4- print car by kilo\n
5- discount
6- print how many car in plice
7- Print total prices car 
8- to print car model 
0 to exi """

        )
        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: " + manifacturingyear[i] + "\nPrice: " + pric[i] + "\n kiloe: " + km[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: " + manifacturingyear[i] + "\nPrice: " + pric[i] + "\n kiloe: " + km[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: " + manifacturingyear[i] + "\nPrice: " + pric[i] + "\n kiloe: " + km[i] + "\n")
                }
            }


            4 -> {
                println("enter the low K: ")
                var lowkilo = readLine()!!.toInt()
                println(" enter the high K: ")
                var highkilo = readLine()!!.toInt()
                for (i in 0 until carType.size)
                    if (km[i] in lowkilo..highkilo)
                        println("Car name:" + carType[i] + "\nCar model: " + model[i] + "\nMade year: " + manifacturingyear[i] + "\nPrice: " + pric[i] + "\n kiloe: " + km[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: " + manifacturingyear[i] + "\n" + "Price before discount: " + pric[i] + "\n" +
                                "Price after discount: " + (pric[i] * dcount / 100 - pric[i]) + "\n kiloe: " + km[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] + "\n year: " + manifacturingyear[i] + "\nPrice: " + pric[i] + "\n k: " + km[i] + "\n")


            }



        }

    }
}