fun main() {
var cType = arrayListOf<String>()
var cmodel = arrayListOf<String>()
var myear = arrayListOf<String>()
var price = arrayListOf<Int>()
var killo = arrayListOf<Int>()
var y = 1
var car = 0
var counter = 0
var prices = 0
var year_ = Regex("([0-3]{4})")
var typ_car = Regex("([a-zA-Z]{1,20})")
while (y == 0) {
print("enter car name ")
var car = readLine()!!.toString()
cType.add(car)
print("enter car model")
cmodel.add(readLine()!!)
}
print("enter car name ")
var carr = readLine()!!.toString()
cType.add(carr)
print("enter car model")
var yar = readLine()!!.toString()
while (!year_.matches(yar)) {
print("enter correct number : ")
yar = readLine()!!.toString()
}
myear.add(yar)
print("enter car price: ")
price.add(readLine()!!.toInt())
prices += price[car]
print("how many kilo ")
var kilo = readLine()!!.toInt()
killo.add(kilo)
print("enter any number : ")
var exit = 1
while (exit != 0) {
println(" \n1- print all car\n2-search name car\n" +
"3- print cars by price range\n4- print car by kilo\n5-make discount\n" +
"6- print how many car in place\n7-Print total prices car \n8- to print car model" +
"\n0 to exit")
var check = readLine()!!.toInt()
when (check) {
0 -> exit = 0
1 -> for (i in 0 until cType.size) { println("Car name:" + cType[i] + "\nCar model: " + cmodel[i] + "\nMade year: " + myear[i] + "\nPrice: " + price[i] + "\n killo: " + killo[i] + "\n") }
2 -> {
println("enter the car that you want to search:")
var c_car = readLine()!!.toString()
for (i in 0 until cType.size)
if (c_car.equals(cType[i]))
println("Car name:" + cType[i] + "\nCar model: " + cmodel[i] + "\nMade year: " + myear[i] + "\nPrice: " + price[i] + "\n killo: " + killo[i] + "\n")
}
3 -> {
println(" enter cheab price: ")
var cheab = readLine()!!.toInt()
println("enter expinsive price: ")
var expinsive = readLine()!!.toInt()
for (i in 0 until cType.size) {
if (cheab <= price[i] && expinsive >= price[i])
println("Car name:" + cType[i] + "\nCar model: " + cmodel[i] + "\nMade year: " + myear[i] + "\nPrice: " + price[i] + "\n killo: " + killo[i] + "\n")
}
}
4 -> {
println("enter the low Kilo: ")
var lowkilo = readLine()!!.toInt()
println(" enter the high Kilo: ")
var highkilo = readLine()!!.toInt()
for (i in 0 until cType.size)
if (killo[i] in lowkilo..highkilo)
println("Car name:" + cType[i] + "\nCar model: " + cmodel[i] + "\nMade year: " + myear[i] + "\nPrice: " + price[i] + "\n killo: " + killo[i] + "\n")
}
5 -> {
println("enter the discount: ")
var dcount = readLine()!!.toInt()
for (i in 0 until cType.size) {
println(
"Car name: " + cType[i] + "\nCar model: " + cmodel[i] + "\nMade year: " + myear[i] + "\n" + "Price before discount: " + price[i] + "\n" +
"Price after discount: " + (price[i] * dcount / 100 - price[i]) + "\n killo: " + killo[i] + "\n"
)
}
}
6 -> println("Total cars is : " + counter + "\n")
7 -> println("Total prices of cars is : " + prices + "\n")
8 -> {
println("enter the model: ")
var temp = readLine()!!
for (i in 0 until cType.size)
if (temp == cmodel[i])
println("Car name:" + cType[i] + "\nCar model: " + cmodel[i] + "\nMade year: " + myear[i] + "\nPrice: " + price[i] + "\n killo: " + killo[i] + "\n")
}
}
}
}