Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
5.9 kB
9
Indexable
Never
import sun.security.pkcs11.wrapper.Functions
import java.text.DecimalFormat
fun main(args: Array<String>) {
    var car_type = arrayListOf<String>()
    var car_modle = arrayListOf<String>()
    var car_year = arrayListOf<String>()
    var car_price = arrayListOf<Double>()
    var car_kilomter = arrayListOf<String>()
    var car_body_number = hashMapOf<Int, String>()
    val year_temp = Regex("\\d{4}")
    val kilomter_temp = Regex("[0-9]*")
    var name_temp = Regex("[A-Za-z]*")
    var test_name = ""
    var test_kilomter = ""
    var test_year = ""

    var x = -1
    var y = -1
    var i = 0;
    var z = 0;
    while (x != 0) {
        println("Enter car name : ")
        test_name = readLine()!!.toString()
        while (!name_temp.matches(test_name)) {

            println("wrong car name, please Enter car name : ")
            test_name = readLine()!!.toString()

        }
        car_type.add(test_name)
        //----------
        println("Enter car modle : ")
        car_modle.add(readLine()!!.toString())
        //------
        println("Enter car year : ")
        test_year = readLine()!!.toString()

        while (!year_temp.matches(test_year)) {

            println("wrong car year, please Enter car year : ")
            test_year = readLine()!!.toString()

        }
        car_year.add(test_year)
        //------
        println("Enter car prise : ")
        car_price.add(readLine()!!.toDouble())
        //------
        println("Enter car kilomters : ")
        test_kilomter = readLine()!!.toString()
        while (!kilomter_temp.matches(test_kilomter)) {

            println("wrong car kilomters, please Enter car kilomters : ")
            test_kilomter = readLine()!!.toString()

        }
        car_kilomter.add(test_kilomter)
        //------
        println("Enter car body number : ")
        car_body_number.put(i, readLine()!!.toString())

        println("if you want to exit prise 0 , if you want to add a new car enter eny number  : ")
        x = readLine()!!.toInt()
        i++


    }
    while (y != 0)
    {
    println("choose from the following:\n" +
            " 1- to print out the full data of car\n" +
            " 2-get car name by body\n" +
            " 3-print car data by prise\n" +
            " 4-print car data by kilomters\n" +
            " 5-\n" +
            " 6-print car numbers\n" +
            " 7-print total cars prise\n" +
            " 8-print car data by prise by modal\n" +
            " 9-print car by name\n" +
            " 0-exit")
    y = readLine()!!.toInt()
    when(y)
    {
        1->{
            for(z in car_type.indices)
            {
                println(car_type[z]+" "+car_modle[z]+" "+car_year[z]+" "+car_price[z]+" "+car_kilomter[z]+" "+car_body_number.getValue(z))
            }
        }
        2->{ println("enter car body number  : ")
                  var body = readLine()!!.toString()
            if(car_body_number.containsValue(body))
            {
                val v = 0
                for (v in car_body_number.keys)
                {
                    if(car_body_number.getValue(v) == body)
                    println("car name is " + car_type[v])
                }

            }
            else
            {
                println("car body number not exist")
            }

        }
        3->{
            println("Enter car price range ")
            print("max : ")
            var max = readLine()!!.toDouble()
            println()
            print("min : ")
            var min = readLine()!!.toDouble()
            for (evl in car_price.indices)
            {
                if(min >= car_price[evl] && car_price[evl] <= max)
                {
                    println(car_type[z]+" "+car_modle[z]+" "+car_year[z]+" "+car_price[z]+" "+car_kilomter[z]+" "+car_body_number.getValue(z))

                }

            }

        }
        4->{
            println("Enter kilomters  range ")
            print("max : ")
            var max = readLine()!!.toDouble()
            println()
            print("min : ")
            var min = readLine()!!.toDouble()
            for (evl in car_kilomter.indices)
            {
                if(min >= car_kilomter[evl].toDouble() && car_price[evl].toDouble() <= max)
                {
                    println(car_type[z]+" "+car_modle[z]+" "+car_year[z]+" "+car_price[z]+" "+car_kilomter[z]+" "+car_body_number.getValue(z))

                }

            }

        }
        5->{

        }
        6->{println(car_type.size)}
        7->{
            var sum=0.0
            for (evl in car_price.indices)
        {
           sum += car_price[evl]
        }
            print("sum")
        }
        8->{
            println("Enter modle  range ")
            print("max : ")
            var max = readLine()!!.toInt()
            println()
            print("min : ")
            var min = readLine()!!.toInt()
            for (evl in car_modle.indices)
            {
                if(min >= car_modle[evl].toInt() && car_modle[evl].toInt() <= max)
                {
                    println(car_type[z]+" "+car_modle[z]+" "+car_year[z]+" "+car_price[z]+" "+car_kilomter[z]+" "+car_body_number.getValue(z))

                }

            }

        }
        9->{println("enter car body number  : ")
            var name = readLine()!!.toString()
            if(car_type.contains(name))
            {
                println("car name is " + car_type[car_type.indexOf(name)])

            }
            else
            {
                println("car name not exist")
            }

        }
        else ->{
            println("wrong number")
        }


    }
    }



}