changes made due to refactoring
This commit is contained in:
+63
-86
@@ -36,6 +36,12 @@ val stars = mutableListOf(starFirst,
|
||||
"Яркий красный сверхгигант на правом плече Охотника. Полурегулярная переменная звезда, находящаяся на поздней стадии эволюции.",
|
||||
listOf(15,29),
|
||||
5.0
|
||||
),
|
||||
Star(4,2,
|
||||
"Бетельгейзе4",
|
||||
"Яркий красный сверхгигант на правом плече Охотника. Полурегулярная переменная звезда, находящаяся на поздней стадии эволюции.",
|
||||
listOf(1,29),
|
||||
960.0
|
||||
))
|
||||
val constellations = mutableListOf(constellationFirst)
|
||||
|
||||
@@ -46,6 +52,20 @@ fun printStarInfo(star: Star){
|
||||
fun printConstellationInfo(constellation: Constellation){
|
||||
println("${constellation.name} ${stars.count{it.constellation == constellation.identifier}} ${constellation.description.take(30)}")
|
||||
}
|
||||
fun getConstellation(): String{
|
||||
println("Введите созвездие:")
|
||||
val constellationsList = constellations.map { it.name }
|
||||
var constellationName: String = readln().lowercase().replaceFirstChar { it.uppercase() }
|
||||
while (true) {
|
||||
if (constellationName in constellationsList){
|
||||
break
|
||||
}
|
||||
println("Список созвездий: ${constellationsList.joinToString(", ")}")
|
||||
constellationName = readln().lowercase().replaceFirstChar { it.uppercase() }
|
||||
|
||||
}
|
||||
return constellationName
|
||||
}
|
||||
|
||||
// Главная функция
|
||||
fun main(){
|
||||
@@ -64,15 +84,12 @@ fun main(){
|
||||
when (input){
|
||||
"1" -> {
|
||||
// Перебираем все звезды и выводим информацию о них
|
||||
for (item in stars){
|
||||
printStarInfo(item)
|
||||
}
|
||||
stars.forEach { printStarInfo(it)}
|
||||
|
||||
}
|
||||
"2" -> {
|
||||
// Перебираем все созвездия и выводим информацию о них
|
||||
for (item in constellations){
|
||||
printConstellationInfo(item)
|
||||
}
|
||||
constellations.forEach { printConstellationInfo(it)}
|
||||
}
|
||||
"3" -> {
|
||||
val map = Array(30) { CharArray(30) { ' ' }}
|
||||
@@ -100,41 +117,24 @@ fun main(){
|
||||
val input = readln()
|
||||
when (input) {
|
||||
"a" -> {
|
||||
println("Введите созвездие:")
|
||||
val constellationsList = constellations.map { it.name }
|
||||
var constellationName: String = readln().lowercase().replaceFirstChar { it.uppercase() }
|
||||
while (true) {
|
||||
if (constellationName in constellationsList){
|
||||
break
|
||||
}
|
||||
else {
|
||||
println("Список созвездий: ${constellationsList.joinToString(", ")}")
|
||||
}
|
||||
constellationName = readln().lowercase().replaceFirstChar { it.uppercase() }
|
||||
|
||||
}
|
||||
val constellationName = getConstellation()
|
||||
println("Введите название звезды:")
|
||||
var starName: String = readln()
|
||||
while (true) {
|
||||
|
||||
if (starName == "" || starName == " ") {
|
||||
println("Введите название звезды")
|
||||
}
|
||||
else {
|
||||
if (starName.isNotBlank()) {
|
||||
break
|
||||
}
|
||||
println("Введите название звезды")
|
||||
starName = readln()
|
||||
}
|
||||
println("Введите описание звезды:")
|
||||
var starDescription: String = readln()
|
||||
while (true) {
|
||||
|
||||
if (starDescription == "" || starDescription == " ") {
|
||||
println("Введите описание звезды")
|
||||
}
|
||||
else {
|
||||
if (starDescription.isNotBlank()) {
|
||||
break
|
||||
}
|
||||
println("Введите описание звезды")
|
||||
starDescription = readln()
|
||||
|
||||
}
|
||||
@@ -146,10 +146,8 @@ fun main(){
|
||||
break
|
||||
|
||||
}
|
||||
else {
|
||||
println("Введите координаты через пробел от 0 до 30")
|
||||
|
||||
}
|
||||
starCoordinates = readln().split(" ").mapNotNull { it.toIntOrNull() }
|
||||
|
||||
}
|
||||
@@ -161,10 +159,9 @@ fun main(){
|
||||
break
|
||||
|
||||
}
|
||||
else {
|
||||
println("Введите размер звезды")
|
||||
|
||||
}
|
||||
|
||||
starSize = readln().toDoubleOrNull()
|
||||
|
||||
|
||||
@@ -172,77 +169,69 @@ fun main(){
|
||||
// Cоздаем id для звезды
|
||||
val starId:Int = (stars.maxOfOrNull {it.identifier } ?:0) + 1
|
||||
// Находим id созвездия
|
||||
val constellationId: Int? = (constellations.find{it.name == constellationName})?.identifier
|
||||
val constellationId: Int? = (constellations.firstOrNull {it.name == constellationName})?.identifier
|
||||
// Создаем звезду
|
||||
stars.add(Star(starId,constellationId!!,starName,starDescription,starCoordinates,starSize))
|
||||
if (constellationId != null) {
|
||||
stars.add(
|
||||
Star(
|
||||
starId,
|
||||
constellationId,
|
||||
starName,
|
||||
starDescription,
|
||||
starCoordinates,
|
||||
starSize
|
||||
)
|
||||
)
|
||||
}
|
||||
// Выводим созданную звезду
|
||||
print("Создана звезда: ")
|
||||
printStarInfo(stars.find {it.identifier == starId}!!)
|
||||
val star = stars.firstOrNull {it.identifier == starId}
|
||||
if (star != null) {
|
||||
printStarInfo(star)
|
||||
}
|
||||
break
|
||||
}
|
||||
"b" -> {
|
||||
|
||||
println("Введите созвездие:")
|
||||
val constellationsList = constellations.map { it.name }
|
||||
var constellationName: String = readln().lowercase().replaceFirstChar { it.uppercase() }
|
||||
while (true) {
|
||||
if (constellationName in constellationsList){
|
||||
break
|
||||
}
|
||||
else {
|
||||
println("Список созвездий: ${constellationsList.joinToString(", ")}")
|
||||
}
|
||||
constellationName = readln().lowercase().replaceFirstChar { it.uppercase() }
|
||||
|
||||
}
|
||||
val constellationName = getConstellation()
|
||||
|
||||
println("Введите новое описание созвездия:")
|
||||
var constellationDescription: String = readln()
|
||||
while (true) {
|
||||
|
||||
if (constellationDescription == "" || constellationDescription == " ") {
|
||||
println("Введите описание созвездия")
|
||||
}
|
||||
else {
|
||||
if (constellationDescription.isNotBlank()) {
|
||||
break
|
||||
}
|
||||
println("Введите описание созвездия")
|
||||
|
||||
constellationDescription = readln()
|
||||
|
||||
}
|
||||
|
||||
val constellation = constellations.find{it.name == constellationName}
|
||||
constellation!!.description = constellationDescription
|
||||
val constellation = constellations.firstOrNull {it.name == constellationName}
|
||||
if (constellation != null) {
|
||||
constellation.description = constellationDescription
|
||||
print("Измененное созвездие: ")
|
||||
printConstellationInfo(constellation)
|
||||
}
|
||||
break
|
||||
|
||||
|
||||
}
|
||||
"c" -> {
|
||||
println("Введите созвездие:")
|
||||
val constellationsList = constellations.map { it.name }
|
||||
var constellationName: String = readln().lowercase().replaceFirstChar { it.uppercase() }
|
||||
while (true) {
|
||||
if (constellationName in constellationsList){
|
||||
break
|
||||
}
|
||||
else {
|
||||
println("Список созвездий: ${constellationsList.joinToString(", ")}")
|
||||
}
|
||||
constellationName = readln().lowercase().replaceFirstChar { it.uppercase() }
|
||||
|
||||
}
|
||||
val constellationName = getConstellation()
|
||||
|
||||
println("Введите звезду:")
|
||||
val starsList = stars.map { it.name }
|
||||
// Находим id созвездия
|
||||
val constellationId: Int? = (constellations.firstOrNull {it.name == constellationName})?.identifier
|
||||
val starsList = stars.filter{it.constellation == constellationId }.map{it.name}
|
||||
var starName: String = readln().lowercase().replaceFirstChar { it.uppercase() }
|
||||
while (true) {
|
||||
if (starName in starsList){
|
||||
break
|
||||
}
|
||||
else {
|
||||
println("Список звезд: ${starsList.joinToString(", ")}")
|
||||
}
|
||||
|
||||
starName = readln().lowercase().replaceFirstChar { it.uppercase() }
|
||||
|
||||
}
|
||||
@@ -269,25 +258,13 @@ fun main(){
|
||||
|
||||
}
|
||||
"5" -> {
|
||||
println("Введите созвездие:")
|
||||
val constellationsList = constellations.map { it.name }
|
||||
var constellationName: String = readln().lowercase().replaceFirstChar { it.uppercase() }
|
||||
while (true) {
|
||||
if (constellationName in constellationsList){
|
||||
break
|
||||
}
|
||||
else {
|
||||
println("Список созвездий: ${constellationsList.joinToString(", ")}")
|
||||
}
|
||||
constellationName = readln().lowercase().replaceFirstChar { it.uppercase() }
|
||||
|
||||
}
|
||||
val constellationName = getConstellation()
|
||||
|
||||
println("Вы точно хотите удалить созведие и звезды? Y/N")
|
||||
val input = readln()
|
||||
if (input in "Yy"){
|
||||
val input = readln().lowercase()
|
||||
if (input == "y"){
|
||||
// Находим id созвездия
|
||||
val constellationId: Int? = (constellations.find{it.name == constellationName})?.identifier
|
||||
val constellationId: Int? = (constellations.firstOrNull {it.name == constellationName})?.identifier
|
||||
stars.removeIf{it.constellation == constellationId}
|
||||
constellations.removeIf{it.name == constellationName}
|
||||
println("Созвездия и звезды успешно удалены")
|
||||
|
||||
Reference in New Issue
Block a user