نايف راشد محمد الدوسري

mail@pastecode.io avatar
unknown
plain_text
2 years ago
5.2 kB
1
Indexable
Never
//نايف راشد الدوسري
fun main() {
    var Cars = arrayListOf<String>()
    var Models = arrayListOf<String>()
    var Price = arrayListOf<Int>()
    var kilo = arrayListOf<Int>()
    var x = 1
    var Car_index = 0
    var prices = 0
    var Y = Regex("([0-9]{4})")
    var k = Regex("([0-9]{0,6})")
    var names = Regex("([a-zA-Z]{1,20})")
    var IndexOfCar = 0
    while (x != 0) {

        print("enter the name of car " + (Car_index + 1) + ": ")
        var cars = readLine()!!.toString()
        while (!names.matches(cars)) {
            print("enter a correct name !!: ")
            cars = readLine()!!.toString()
        }
        Cars.add(cars)
        print("enter the car  " + (Car_index + 1) + " model: ")
        Models.add(readLine()!!)
        print("enter the car  " + (Car_index + 1) + " price: ")
        Price.add(readLine()!!.toInt())
        prices += Price[Car_index]
        print("car  " + (Car_index + 1) + " how many kilometers? ")
        var kilos = readLine()!!.toInt()
        while (!k.matches(kilos.toString())) {
            print("enter a correct kilometers !!: ")
            kilos = readLine()!!.toInt()
        }
        
        println("PRESS 0 TO STOP\nANY KEY TO CONTINUE: ")
        x = readLine()!!.toInt()
        Car_index++

    }

    var option = 1
    while (option != 0) {
        println(
            "please choose: \n1 to print all cars\n2 to search cars by names\n" +
                    "3 to print cars by price range\n4 to print cars by kilometers\n5 to make discount\n" +
                    "6 to print how many car in the showroom\n7 to print total prices of cars\n8 to print cars by model" +
                    "\n0 to exit"
        )
        var choose = readLine()!!.toInt()
        when (choose) {

            0 -> option = 0

            1 -> for (i in 0 until Cars.size) {
                println("Car name:"+Cars[i] + "\nCar model: " + Models[i] + "\nMade year: "  + "\nPrice: " + Price[i] + "\nOdo meters: " + kilo[i]+"\n")
            }
            2 -> {
                println("please enter the car that you want to search:")
                var temp_car = readLine()!!.toString()
                for (i in 0 until Cars.size)
                    if (temp_car.equals(Cars[i]))
                        println("Car name:"+Cars[i] + "\nCar model: " + Models[i] + "\nMade year: "  + "\nPrice: " + Price[i] + "\nOdo meters: " + kilo[i]+"\n")
            }
            3 -> {
                var temp_price =0
                println("please enter the lowest price: ")
                var low_price = readLine()!!.toInt()
                println("please enter the highest price: ")
                var high_price = readLine()!!.toInt()
                if(low_price > high_price){
                    temp_price = low_price
                    low_price = high_price
                    high_price = temp_price
                }

                for (i in 0 until Cars.size) {
                    if (Price[i] in low_price..high_price)
                        println("Car name:"+Cars[i] + "\nCar model: " + Models[i] + "\nMade year: " + "\nPrice: " + Price[i] + "\nOdo meters: " + kilo[i]+"\n")
                }
            }
            4 -> {
                var temp_kilos =0
                println("please enter the lowest Kilometers: ")
                var low_kilos = readLine()!!.toInt()
                println("please enter the highest Kilometers: ")
                var high_kilos1 = readLine()!!.toInt()
                if(low_kilos > high_kilos1){
                    temp_kilos = low_kilos
                    low_kilos = high_kilos1
                    high_kilos1 = temp_kilos
                }
                for (i in 0 until Cars.size)
                    if (kilo[i] in low_kilos..high_kilos1)
                        println("Car name:" + Cars[i] + "\nCar model: " + Models[i] + "\nMade year: "  + "\nPrice: " + Price[i] + "\nOdo meters: " + kilo[i]+"\n")
            }

            5 ->{
                println("please enter the discount: ")
                var discount = readLine()!!.toInt()
                for (i in 0 until Cars.size) {
                    println(
                        "Car name: "+Cars[i] + "\nCar model: " + Models[i] + "\nMade year: "  + "\n" + "Price before discount: " + Price[i] + "\n" +
                                "Price after discount: " + (Price[i]*discount/100-Price[i]) +"\nOdo meters: "+ kilo[i]+"\n"
                    )
                }

            }

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

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

            8 -> {
                println("please enter the model: ")
                var temp_model = readLine()!!
                for (i in 0 until Cars.size)
                    if (temp_model == Models[i])
                        println("Car name:"+Cars[i] + "\nCar model: " + Models[i] + "\nMade year: "  + "\nPrice: " + Price[i] + "\nOdo meters: " + kilo[i]+"\n")
            }

        }
    }
}