mirror of
https://github.com/ZhigalskiiIvan/TextStatisticsProject.git
synced 2024-11-21 23:01:52 +03:00
textReader done
This commit is contained in:
parent
67c7a9dc6c
commit
38e29bcd52
@ -1,3 +1,4 @@
|
||||
import java.io.File
|
||||
import java.util.Scanner
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
@ -5,21 +6,115 @@ val scanner = Scanner(System.`in`)
|
||||
|
||||
object StatisticBuilder {
|
||||
|
||||
fun buildGraphic() {}
|
||||
fun askAndExecuteSelfCommands() {}
|
||||
|
||||
fun printStatisticsInConsole() {}
|
||||
private fun buildGraphic() {}
|
||||
|
||||
private fun printStatisticsInConsole() {}
|
||||
|
||||
}
|
||||
|
||||
|
||||
object TextReader {
|
||||
fun readFromConsole(): String {
|
||||
TODO()
|
||||
fun askAndExecuteSelfCommands() {
|
||||
|
||||
println("Where do you want to add the text: from the console of a file?")
|
||||
when (readln().lowercase()) {
|
||||
"console" -> readFromConsole()
|
||||
"file" -> readFromFile()
|
||||
"return" -> return
|
||||
else -> {
|
||||
println("Repeat input or print \"return\" to return in main menu:")
|
||||
askAndExecuteSelfCommands()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun readFromConsole() {
|
||||
|
||||
println("Input name of a text:")
|
||||
val name = readln()
|
||||
|
||||
println("Input a text content:")
|
||||
var content: String = ""
|
||||
readCycle@ while (true) {
|
||||
val nextPart = scanner.next()
|
||||
if (nextPart.isEmpty()) content += nextPart
|
||||
else break@readCycle
|
||||
}
|
||||
|
||||
correctInputQuestion@ while (true) {
|
||||
print("Input was correct?[yes, no]: ")
|
||||
when (readln()) {
|
||||
"yes" -> addTextToData(name, content)
|
||||
"no" -> readFromConsole()
|
||||
"return" -> return
|
||||
else -> {
|
||||
println("Input only \"yes\" or \"no\" or \"return\" if you want to exit in main menu:")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun readFromFile() {
|
||||
|
||||
println("Input a name of a text:")
|
||||
val name = readln()
|
||||
|
||||
val contentsFile: File
|
||||
pathReadCycle@ while (true) {
|
||||
println("Input a path to file:")
|
||||
val filePath = readln()
|
||||
val testFile = File(filePath)
|
||||
|
||||
when {
|
||||
filePath == "return" -> return
|
||||
!testFile.exists() -> {
|
||||
println("File path incorrect. Repeat input or enter \"return\" to return in main menu:")
|
||||
continue@pathReadCycle
|
||||
}
|
||||
|
||||
else -> {
|
||||
contentsFile = testFile
|
||||
break@pathReadCycle
|
||||
}
|
||||
}
|
||||
}
|
||||
val content = contentsFile.readText()
|
||||
|
||||
correctInputQuestion@ while (true) {
|
||||
print("Input was correct?[yes, no]: ")
|
||||
when (readln()) {
|
||||
"yes" -> addTextToData(name, content)
|
||||
"no" -> readFromFile()
|
||||
"return" -> return
|
||||
else -> {
|
||||
println("Input only \"yes\" or \"no\" or \"return\" if you want to exit in main menu:")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun addTextToData(textName: String, content: String) {
|
||||
TextData.addNewText(textName, content)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class TextData() {
|
||||
data class Text(private val name: String, private val sentencesCount: Int) {
|
||||
|
||||
val sentencesList = listOf<Sentence>()
|
||||
|
||||
fun getSentencesCount() {}
|
||||
|
||||
data class Sentence(val wordsCount: Int) {}
|
||||
|
||||
}
|
||||
|
||||
|
||||
object TextData {
|
||||
private val textsList = mutableListOf<Text>()
|
||||
|
||||
fun addNewText(textName: String, content: String) {}
|
||||
@ -30,17 +125,6 @@ class TextData() {
|
||||
fun returnListOfSentences(text: Text): List<Text.Sentence> {
|
||||
TODO()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Text(private val name: String, private val sentencesCount: Int) {
|
||||
|
||||
val sentencesList = listOf<Sentence>()
|
||||
|
||||
fun getSentencesCount() {}
|
||||
|
||||
class Sentence(val words_count: Int) {}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -53,8 +137,8 @@ object CommandCenter {
|
||||
println("bye!")
|
||||
exitProcess(0)
|
||||
}),
|
||||
ADD_TEXT({ println("add") }),
|
||||
SHOW_STATISTICS({ println("sow") }),
|
||||
ADD_TEXT({ TextReader.askAndExecuteSelfCommands() }),
|
||||
SHOW_STATISTICS({ StatisticBuilder.askAndExecuteSelfCommands() }),
|
||||
REMOVE_TEXT({ println("remove") })
|
||||
}
|
||||
|
||||
@ -67,11 +151,8 @@ object CommandCenter {
|
||||
else ::readCommandFromConsole
|
||||
}
|
||||
|
||||
fun executeCommand() {}
|
||||
|
||||
}
|
||||
|
||||
|
||||
fun main() {
|
||||
|
||||
mainCycle@ while (true) {
|
||||
|
Loading…
Reference in New Issue
Block a user