Untitled
unknown
plain_text
4 years ago
6.4 kB
20
Indexable
fun main () {
var cName = arrayListOf<String>()
var cType = arrayListOf<String>()
var cDate = arrayListOf<String>()
var cPrice = arrayListOf<Int>()
var cKilo = arrayListOf<String>()
var cstructure: HashMap<Int, String> = HashMap()
var NameFormat = Regex("([a-zA-Z]{1,25})")
var DateFormat = Regex("([0-9]{4})")
var KiloFormat = Regex("([0-9]{0,9})")
var CheckModel = ""
var CheckKilo = ""
var CheckName = ""
var i = 1
var j = 0
while (i == 1) {
while (true) {
print("Enter the name of car: ")
CheckName = readLine()!!.toString()
if (!NameFormat.matches(CheckName)) {
print("Please choose the correct, again! \n")
} else {
cName.add(CheckName)
break
}
}
print("Enter the type of car: ")
cType.add(readLine()!!.toString())
while (true) {
print("Enter wich year of the car: ")
CheckModel = readLine()!!.toString()
if (!DateFormat.matches(CheckModel)) {
print("Please choose the correct, again! \n")
} else {
cDate.add(CheckModel)
break
}
}
print("Enter the price: ")
cPrice.add(readLine()!!.toInt())
while (true) {
print("Enter the kilo: ")
CheckKilo = readLine()!!.toString()
if (!KiloFormat.matches(CheckKilo)) {
print("Please choose the correct, again! \n")
} else {
cKilo.add(CheckKilo)
break
}
}
print("Enter the car structure: ")
cstructure.put((j), readLine()!!.toString())
j++
print("Continue = 1\nExit = 0")
i = readLine()!!.toInt()
if (i == 0) {
break;
}
}
while (true) {
print("\nPrint all Cars data = 1\nPrint by structure Number = 2\nPrint by range of price = 3\nPrint by range of Kilos = 4\nPrint with discount = 5\nPrint Total cars = 6\nPrint sum prices of cars = 7\nPrint by car model = 8\nPrint by car name = 9\nExit = 0\n")
var x = readLine()!!.toInt()
if (x == 0) {
print("\nThe program has been closed..")
break
}
when (x) {
1 -> {
for (i in 0..cName.size - 1) {
println("Car Name: " + cName[i] + " Car Type: " + cType[i] + " Car Date: " + cDate[i] + " carPrice: " + cPrice[i] + " Car Kilos: " + cKilo[i] + " Car structure: " + cstructure[i])
}
}
2 -> {
print("Enter the structure number to search: ")
var structure = readLine()!!.toString()
for (i in 0..cName.size - 1) {
if (structure == cstructure[i])
println("Car Name: |" + cName[i] + " Car Type: " + cType[i] + " Car Date: " + cDate[i] + " carPrice: " + cPrice[i] + " Car Kilos: " + cKilo[i] + " Car structure: " + cstructure[i])
}
}
3 -> {
print("Enter the range of price #1: ")
var price1 = readLine()!!.toInt()
print("Enter the range of price #2: ")
var price2 = readLine()!!.toInt()
for (i in 0..cName.size - 1) {
if (cPrice[i] >= price1 && cPrice[i] <= price2) {
println("Car Name: " + cName[i] + " Car Type: " + cType[i] + " Car Date: " + cDate[i] + " carPrice: " + cPrice[i] + " Car Kilos: " + cKilo[i] + " Car structure: " + cstructure[i])
}
}
}
4 -> {
print("Enter the range of kilos #1 ")
var kilo1 = readLine()!!.toString()
print("Enter the range of kilos #2 ")
var kilo2 = readLine()!!.toString()
for (i in 0..cName.size - 1) {
if (cKilo[i] >= kilo1 && cKilo[i] <= kilo2) {
println("Car Name: " + cName[i] + " Car Type: " + cType[i] + " Car Date: " + cDate[i] + " carPrice: " + cPrice[i] + " Car Kilos: " + cKilo[i] + " Car structure: " + cstructure[i])
}
}
}
5 -> {
print("Enter the discount you want in %\nexample: 5% ")
var discount = readLine()!!.toDouble() / 100
var disApply = 0.0
for (i in 0..cName.size - 1) {
disApply = cPrice[i] * discount
println("Car Name: " + cName[i] + " Car Type: " + cType[i] + " Car Date: " + cDate[i] + " carPrice before discount: " + cPrice[i] + " carPrice after discount: " + (cPrice[i] - disApply) + " Car Kilos: " + cKilo[i] + " Car structure: " + cstructure[i])
}
}
6 -> {
println("Total cars: " + cName.size)
}
7 -> {
println("Sum of cars prices: " + cPrice.sum())
}
8 -> {
print("Enter the range of model #1 ")
var model1 = readLine()!!.toString()
print("Enter the range of model #2 ")
var model2 = readLine()!!.toString()
for (i in 0..cName.size - 1) {
if (cDate[i] >= model1 && cDate[i] <= model2) {
println("Car Name: " + cName[i] + " Car Type: " + cType[i] + " Car Date: " + cDate[i] + " carPrice: " + cPrice[i] + " Car Kilos: " + cKilo[i] + " Car structure: " + cstructure[i])
}
}
}
9 -> {
print("Enter the car name you want ")
var name = readLine()!!.toString()
for (i in 0..cName.size - 1) {
if (name == cName[i]) {
println("Car Name: " + cName[i] + " Car Type: " + cType[i] + " Car Date: " + cDate[i] + " carPrice: " + cPrice[i] + " Car Kilos: " + cKilo[i] + " Car structure: " + cstructure[i])
}
}
}
}
}
}
Editor is loading...