Untitled
unknown
plain_text
4 years ago
3.4 kB
10
Indexable
fun main() {
var manufacturers = arrayListOf<String>()
var models = arrayListOf<String>()
var years = arrayListOf<Int>()
var prices = arrayListOf<Double>()
var KMs = arrayListOf<Int>()
var VINs = hashMapOf<Int, String>()
while (true) {
print("Enter car manufacturer (or 'd' when done): ")
var manufacturer = readLine()!!
if (manufacturer == "d")
break
var model: String;
do {
print("Enter car model: ")
model = readLine()!!
}
while (!model.matches("[A-Za-z]*$".toRegex()))
var year: String
do {
print("Enter car year: ")
year = readLine()!!
}
while (!year.matches("[0-9]{4}".toRegex()))
var km: String
do {
print("Enter car kilometers: ")
km = readLine()!!
}
while (!km.matches("[0-9]+".toRegex()))
print("Enter car price: ")
var price = readLine()!!.toDouble()
print("Enter car VIN: ")
var VIN = readLine()!!
manufacturers.add(manufacturer)
models.add(model)
years.add(year.toInt())
prices.add(price)
KMs.add(km.toInt())
VINs.put(models.size-1, VIN)
}
do {
println("Commands list:")
println("1- View cars list")
println("2- Find car by VIN")
println("3- Find cars by price range")
println("4- Find cars by kilometers range")
println("5- Apply a specified discount to all cars")
println("6- Count cars")
println("7- Total car prices")
println("8- Find cars by year range")
println("9- Search car by name")
var cmd = readLine()!!
if (cmd == "c")
break
when (cmd.toInt()) {
1 -> {
for (i in 0 until models.size) {
println("${years[i]} ${manufacturers[i]} ${models[i]} ${KMs[i]} km with VIN: ${VINs.get(i)} and price of: ${prices[i]}")
}
}
2 -> {
print("Enter car VIN: ")
var vin = readLine()!!
for (i in 0 until models.size) {
if (VINs.get(i) == vin) {
println("${models[i]}")
break
}
}
}
3 -> {
print("Enter start price: ")
val sPrice = readLine()!!.toDouble()
print("Enter end price: ")
val ePrice = readLine()!!.toDouble()
for (i in 0 until models.size) {
if (prices[i] in sPrice..ePrice) {
println("${years[i]} ${manufacturers[i]} ${models[i]} ${KMs[i]} km with VIN: ${VINs.get(i)} and price of: ${prices[i]}")
}
}
}
4 -> {
}
5 -> {
}
6 -> {
}
7 -> {
}
8 -> {
}
9 -> {
}
else -> {
println("Enter a valid command (1-9) or 'c' to close")
}
}
} while (true)
}
Editor is loading...