thamer aldosari

 avatar
unknown
plain_text
2 years ago
5.6 kB
3
Indexable
fun main(args:Array<String>) {
    println("welcme to cars showeroom thamer  ")
    var Cars = arrayListOf<String>()
    var Models = arrayListOf<String>()
    var Year = arrayListOf<String>()
    var Price = arrayListOf<Int>()
    var Meters = 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("plase enter the name of car Number " + (Car_index + 1) + ": ")
        var cars = readLine()!!.toString()
        while (!names.matches(cars)) {
            print("enter a correct name !!: ")
            cars = readLine()!!.toString()
        }
        Cars.add(cars)

        print("plase enter the car Number  " + (Car_index + 1) + " model: ")
        Models.add(readLine()!!)

        print("plase enter the car Number " + (Car_index + 1) + " year: ")
        var year = readLine()!!.toString()
        while (!Y.matches(year)) {
            print("enter a correct year make !!: ")
            year = readLine()!!.toString()
        }
        Year.add(year)
        print("plase enter the car Number  " + (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("plase enter a correct kilometers !!: ")
            kilos = readLine()!!.toInt()}
        Meters.add(kilos)
        println("PRESS 0 TO STOP\nEnter Number 1 Continue: ")
        x = readLine()!!.toInt()
        Car_index++}
    var option = 1
    while (option != 0) {
        print("----------------------------")
        println(": \n1  print all cars\n2  search cars by names\n" +
                    "3  print cars by price range\n4  print cars by kilometers\n5  make discount\n" +
                    "6  print how many car in the showroom\n7  print total prices of cars\n8  print cars by model" +
                    "\n0 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: " + Year[i] + "\nPrice: " + Price[i] + "\nOdo meters: " + Meters[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: " + Year[i] + "\nPrice: " + Price[i] + "\nOdo meters: " + Meters[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: " + Year[i] + "\nPrice: " + Price[i] + "\nOdo meters: " + Meters[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 (Meters[i] in low_kilos..high_kilos1)
                        println("Car name:" + Cars[i] + "\nCar model: " + Models[i] + "\nMade year: " + Year[i] + "\nPrice: " + Price[i] + "\nOdo meters: " + Meters[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: " + Year[i] + "\n" + "Price before discount: " + Price[i] + "\n" + "Price after discount: " + (Price[i]*discount/100-Price[i]) +"\nOdo meters: "+ Meters[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: " + Year[i] + "\nPrice: " + Price[i] + "\nOdo meters: " + Meters[i]+"\n")
            }

        }

}
}
Editor is loading...