Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
6.0 kB
4
Indexable
Never
fun main() {
    var cartype= arrayListOf<String>()
    var carModel= arrayListOf<String>()
    var year= arrayListOf<String>()
    var price= arrayListOf<Int>()
    var kilos= arrayListOf<String>()
    var Bodynumber= hashMapOf<Int,String>()
    var reg_kilos=Regex("""[0-9]+|\s+""")
    var reg_year=Regex("\\d{4}")
    var i=0
    var kilometer=""
    var year1=""
    while(true){
        println("enter car type")
        cartype.add(readLine()!!)
        println("enter car model")
        carModel.add(readLine()!!)
        println("enter car year")
        year1=readLine()!!
        while(true){
            if (!reg_year.matches(year1)){
                println("plz enter 4 numbers:")
                year1= readLine()!!

            }
            else {
                year.add(year1)
                break
            }
        }

        println("enter car price")
        price.add(readLine()!!.toInt())
        println("enter car kilos")
        kilometer=readLine()!!
        while(true){
            if (!reg_kilos.matches(kilometer)){
                println("plz enter a number:")
                kilometer= readLine()!!
            }
            else {
                kilos.add(kilometer)
                break
            }
        }
        println("enter car body number and car name")
        Bodynumber.put(i, readLine()!!)
        i++
        println("do you want to add another car? press any key to add more cars or 0 to stop")
        var choice= readLine()!!
        if (choice=="0") break
    }

    print("Choose from 1 - 9")
    var choose= readLine()!!.toInt()
    while (true) {
        when (choose) {
            1 -> {
                for (i in 0 until carModel.size) {
                    println("Car type: ${cartype[i]}\nCar model:${carModel[i]}\nYear: ${year[i]}\nPrice: ${price[i]}\nNumber of kilos: ${kilos[i]}\nBodyNumber: ${Bodynumber[i]}")
                }
            }
            2 -> {
                print("enter carbody number")
                var number = readLine()!!
                var found = 0
                for ((key, value) in Bodynumber) {
                    if (value == number) found == key
                    break
                }
                println("Car type: ${cartype[found]}\nCar model:${carModel[found]}\nYear: ${year[found]}\nPrice: ${price[found]}\nNumber of kilos: ${kilos[found]}\nBodyNumber: ${Bodynumber[found]}")
            }
            3 -> {
                print("enter minimum price")
                var min = readLine()!!.toInt()
                print("enter maximum price")
                var max = readLine()!!.toInt()
                for (i in 0 until carModel.size) {
                    if (price[i] <= max && price[i] >= min) {
                        println("Car type: ${cartype[i]}\nCar model:${carModel[i]}\nYear: ${year[i]}\nPrice: ${price[i]}\nNumber of kilos: ${kilos[i]}\nBodyNumber: ${Bodynumber[i]}")
                    }
                }
            }
            4 -> {
                print("enter minimum kilos")
                var min = readLine()!!.toInt()
                print("enter maximum kilos")
                var max = readLine()!!.toInt()
                for (i in 0 until carModel.size) {
                    if (kilos[i].toInt() <= max && kilos[i].toInt() >= min) {
                        println("Car type: ${cartype[i]}\nCar model:${carModel[i]}\nYear: ${year[i]}\nPrice: ${price[i]}\nNumber of kilos: ${kilos[i]}\nBodyNumber: ${Bodynumber[i]}\n--------------------------------------------------------------")
                    }
                }
            }
            5 -> {
                print("enter the disccount ammount")
                var dis = readLine()!!.toDouble()
                println("before discount")
                for (i in 0 until carModel.size) {
                    println("Car type: ${cartype[i]}\nCar model:${carModel[i]}\nYear: ${year[i]}\nPrice: ${price[i]}\nNumber of kilos: ${kilos[i]}\nBodyNumber: ${Bodynumber[i]}")
                }
                println("after discount")
                for (i in 0 until carModel.size) {
                    println("Car type: ${cartype[i]}\nCar model:${carModel[i]}\nYear: ${year[i]}\nPrice: ${price[i] - (price[i] * (dis / 100))}\nNumber of kilos: ${kilos[i]}\nBodyNumber: ${Bodynumber[i]}")
                }
            }
            6 -> {
                println("number off cars: ${carModel.size}")
            }
            7 -> {
                var sum = 0
                for (i in 0 until carModel.size) {
                    sum += price[i]
                }
                print("the sum of all cars: $sum")
            }
            8 -> {
                print("enter minimum model")
                var min = readLine()!!.toInt()
                print("enter maximum model")
                var max = readLine()!!.toInt()
                for (i in 0 until carModel.size) {
                    if (carModel[i].toInt() <= max && carModel[i].toInt() >= min) {
                        println("Car type: ${cartype[i]}\nCar model:${carModel[i]}\nYear: ${year[i]}\nPrice: ${price[i]}\nNumber of kilos: ${kilos[i]}\nBodyNumber: ${Bodynumber[i]}")
                    }
                }
            }
            9 -> {
                println("enter the name of the car: ")
                var search = readLine()!!
                for (i in 0 until carModel.size) {
                    if (search == carModel[i]) {
                        println("Car type: ${cartype[i]}\nCar model:${carModel[i]}\nYear: ${year[i]}\nPrice: ${price[i]}\nNumber of kilos: ${kilos[i]}\nBodyNumber: ${Bodynumber[i]}")
                    }
                }
            }
        }
        print("do you want to do another search?press any key or 0 to stop")
        var stop= readLine()!!
        if (stop=="0") break
    }
}