Untitled
unknown
plain_text
3 years ago
8.0 kB
1
Indexable
fun main(args:Array<String>) { var vehicle_type = arrayListOf<String>() var model_car = arrayListOf<String>() var manufacturing_year = arrayListOf<Int>() var carPrice = arrayListOf<Int>() var klioM = arrayListOf<Int>() var StructureNo = arrayListOf<Int>() var StructureNo_M = hashMapOf<Int,String>() var choice: Int var type: String var model: String var year: Int var price: Int var kilo: Int var Structureno: Int println("1- add new car \n 2- View all cars \n 3- Retrieval of a car by chassis number \n 4- View all vehicle data by price \n "+ "5- View all vehicle data by kilometer \n 6- Specific discount and display all car data before and after discount \n" + "7- View the number of cars availabl \n 8- Show total car values\n 9- View data for all cars by model \n 10-exit ") choice = readLine()!!.toInt() while (choice != 10) { when(choice){ 1 -> { print("Enter vehicle type: ") type = readLine()!!.toString() while (!Regex("[a-zA-Z]+").matches(type.toString())) { print(" Input again vehicle type: ") type = readLine()!! } vehicle_type.add(type) print("Enter model car: ") model = readLine()!!.toString() model_car.add(model) print("Input manufacturing year: ") year = readLine()!!.toInt() while (!Regex("\\d{4}").matches(year.toString())) { print(" Input again year: ") year = readLine()!!.toInt() } manufacturing_year.add(year) print("Input price car : ") price = readLine()!!.toInt() carPrice.add(price) print("Enter kilo meters: ") kilo = readLine()!!.toInt() while (!Regex("\\d+").matches(kilo.toString())) { println(" Input again the kilo ") kilo = readLine()!!.toInt() } klioM.add(kilo) println("Input StructureNo number: ") Structureno = readLine()!!.toInt() StructureNo.add(Structureno) StructureNo_M.put(Structureno, type) } 2 -> { print("Input car Structure No: ") var search = readLine()!!.toInt() var found = false for (key in StructureNo_M.keys) { if (key == search) { found = true println("car found is " + StructureNo_M.get(key)) break } } if (!found) { println("car not found") } } 3 -> { print("Input min price: ") var min = readLine()!!.toInt() print("Input max price: ") var max = readLine()!!.toInt() val found_cars = arrayListOf<String>() for (i in 0 until carPrice.size) { if (min <= carPrice[i] && max >= carPrice[i]) { found_cars.add("${i+1}- ${vehicle_type[i]}") } } } 4 -> { print("Input min kilo: ") var min = readLine()!!.toInt() print("Input max kilo: ") var max = readLine()!!.toInt() val found_cars = arrayListOf<String>() for (i in 0 until klioM.size) { if (min <= klioM[i].toInt() && max >= klioM[i].toInt()) { found_cars.add("* ${vehicle_type[i]}") } } if (found_cars.size > 0) { println(found_cars) } else { println("no cars in this range of Kilo counter") } } 5 -> { print("Input discount: ") var discount = readLine()!!.toInt() var full_price_before = 0 var full_price_after = 0 for (i in 0 until carPrice.size) { full_price_before += carPrice[i] } full_price_after = full_price_before - (full_price_before * discount) println("price before discount is " + full_price_before) println("price after discount is " + full_price_after) } 6 -> { println("number of cars is " + vehicle_type.size) } 7 -> { var full_price = 0 for (i in 0 until carPrice.size) { full_price += carPrice[i] } println("Full price of cars is: $full_price") } 8 -> { print("Input min Year: ") var min = readLine()!!.toInt() print("Input max Year: ") var max = readLine()!!.toInt() val found_cars = arrayListOf<String>() for (i in 0 until manufacturing_year.size) { if (min <= manufacturing_year[i] && max > manufacturing_year[i]) { found_cars.add("${i+1}- ${vehicle_type[i]}") } } if (found_cars.size > 0) { println(found_cars) } else { println("no cars in this range of dates") } } 9 -> { print("Input car name: ") var search = readLine()!! var found = false for (value in StructureNo_M.values) { if (value.equals(search)) { println("car found is:$value") found = true break } } if (!found) { println("car not found") } } 10 -> { choice = readLine()!!.toInt() } } println("\n\n1- add new car\n2-View all cars\n3- Retrieval of a car by chassis number\n4-View all vehicle data by price\n"+ "5-View all vehicle data by kilometer\n6-Specific discount and display all car data before and after discount\n" + "7-View the number of cars available\n8-Show total car values\n9-View data for all cars by model\n10-exit") choice = readLine()!!.toInt() } }
Editor is loading...