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