Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
5.6 kB
2
Indexable
Never
// exam1  saad alqarni
fun main(args: Array<String>) {

    var typeArray = ArrayList<String>()
    var modelArray = ArrayList<String>()
    var yearArray = ArrayList<Int>()
    var priceArray = ArrayList<Double>()
    var kiloArray = ArrayList<Int>()
    var bodyNoArray = hashMapOf<Int,String>()

    var x = 1
    var i = 0
    while(x != 0) {
        print("Enter car " + (i+1) + " type :")
        typeArray.add(readLine()!!)

        print("Enter car " + (i+1) + " model :")
        modelArray.add(readLine()!!)

        print("Enter car " + (i+1) + " year :")
        yearArray.add(readLine()!!.toInt())

        print("Enter car " + (i+1) + " price :")
        priceArray.add(readLine()!!.toDouble())

        print("Enter car " + (i+1) + " kilometers :")
        kiloArray.add(readLine()!!.toInt())

        println("Enter car" + (i+1) + " body number :")
        bodyNoArray.put(i, readLine()!!)

    }

    print(" choose your inquiry from the list below :\n" +
            " 1-to print out full data of cars\n" +
            " 2-to print out car name by body No.\n" +
            " 3-to print out a list of the cars info with specific range of their prices\n" +
            " 4-to print out a list of the cars info with specific range of their kilometers\n" +
            " 5-to print out a list of the cars info with specific discount\n" +
            " 6-to print out a list of the cares in the branch\n" +
            " 7-to print out a list of the total prices of all cars\n" +
            " 8-to print out a list of the cars info with specific range of their model\n" +
            " 9-to print out a specific car by it's name\n")
    var stop = 'a'
    do{
        print("Enter Your choice :")
        var selec = readLine()!!.toInt()
        when(selec) {
            1 -> {
                for (i in 0 until typeArray.size) {
                    println("car " + (i + 1) + "information: \n" + typeArray[i] + "  " + modelArray[i] + "  " + yearArray[i]
                                + "  " + priceArray[i] + "  " + kiloArray[i] + " " + bodyNoArray.get(i))
                }

            }
            2 -> {
                println("enter a number of body: ")
                var bodyNo = readLine()!!
                for (i in 0 until typeArray.size) {
                    if (bodyNoArray.get(i) == bodyNo)
                        println("car name is: " + typeArray[i])
                }

            }
            3 -> {
                println("enter a range of prices: ")
                println("From: ")
                var from = readLine()!!.toDouble()
                println("To: ")
                var to = readLine()!!.toDouble()
                for (i in 0 until typeArray.size) {
                    if (priceArray[i] in from..to)
                        println("car " + (i + 1) + "information: \n" + typeArray[i] + "  " + modelArray[i] + "  " + yearArray[i]
                                + "  " + priceArray[i] + "  " + kiloArray[i] + " " + bodyNoArray.get(i))
                }
            }
            4 -> {
                println("enter a range of kilometers: ")
                println("From: ")
                var from = readLine()!!.toInt()
                println("To: ")
                var to = readLine()!!.toInt()
                for (i in 0 until typeArray.size) {
                    if (kiloArray[i] in from..to)
                        println("car " + (i + 1) + "information: \n" + typeArray[i] + "  " + modelArray[i] + "  " + yearArray[i]
                                + "  " + priceArray[i] + "  " + kiloArray[i] + " " + bodyNoArray.get(i))
                }
            }
            5 -> {
                println("enter a discount percentage: ")
                var dis = readLine()!!.toInt()
                var newpric = 0.0
                for (i in 0 until typeArray.size) {
                    newpric = priceArray[i] - ((priceArray[i] * dis)/100)
                    println("car " + (i + 1) + "information: \n" + typeArray[i] + "  " + modelArray[i] + "  " + yearArray[i]
                                    + "  " + priceArray[i] + "  " + kiloArray[i] + " " + bodyNoArray.get(i) +
                                    "price after discount: " + newpric )
                }
            }
            6 -> {
                var count = 0
                for (i in 0 until typeArray.size) {
                    count++
                }
                println(count)
            }
            7 -> {
                var totalPrices = 0.0
                for (i in 0 until typeArray.size) {
                    totalPrices += priceArray[i]
                }
                println("total amount of cars prices is: " + totalPrices)

            }
            8 -> {

            }
            9 -> {
                println("enter car name: ")
                var carname = readLine()!!
                for (i in 0 until typeArray.size) {
                    if (typeArray[i] == carname)
                        println("car information: \n" + typeArray[i] + "  " + modelArray[i] + "  " + yearArray[i]
                                + "  " + priceArray[i] + "  " + kiloArray[i] + " " + bodyNoArray.get(i))

                }

            }
            else -> println("ENTER A CORRECT NUMBER !\nOR N to STOP")
        }
        println("do you want to make another inquiry ?\nY/N")
        stop= readLine()!!.single()

    }while (stop == 'Y' || stop == 'y')
}


}