This commit is contained in:
KP9lK 2024-11-11 23:10:52 +03:00
commit 4cbe9c453e
12 changed files with 174 additions and 0 deletions

29
.gitignore vendored Normal file
View File

@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

3
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="ReplaceUntilWithRangeUntil" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
</profile>
</component>

10
.idea/kotlinc.xml Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Kotlin2JvmCompilerArguments">
<option name="jvmTarget" value="1.8" />
</component>
<component name="KotlinCommonCompilerArguments">
<option name="apiVersion" value="2.0" />
<option name="languageVersion" value="2.0" />
</component>
</project>

View File

@ -0,0 +1,17 @@
<component name="libraryTable">
<library name="KotlinJavaRuntime" type="repository">
<properties maven-id="org.jetbrains.kotlin:kotlin-stdlib:2.0.0" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.0.0/kotlin-stdlib-2.0.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.0.0/kotlin-stdlib-2.0.0-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.0.0/kotlin-stdlib-2.0.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-sources.jar!/" />
</SOURCES>
</library>
</component>

6
.idea/misc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_20" default="true" project-jdk-name="corretto-20" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/ex1.iml" filepath="$PROJECT_DIR$/ex1.iml" />
</modules>
</component>
</project>

15
ex1.iml Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/testResources" type="java-test-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component>
</module>

36
src/Main.kt Normal file
View File

@ -0,0 +1,36 @@
import data.models.User
import data.repository.UserRepository
import data.repository.UserRepositoryImpl
fun main() {
val repository = UserRepositoryImpl()
while (true) {
println("1.Вывести пользователей\n2.Добавить пользователя")
when (readln().toInt()) {
1 -> printAllUsers(repository)
2 -> addUser(repository)
else -> break
}
}
}
fun printAllUsers(userRepository: UserRepository) {
userRepository.getAllUsers().forEach { user ->
println("${user.id} ${user.email} ${user.lastName} ${user.firstName}")
}
}
fun addUser(userRepository: UserRepository){
println("Введите почту")
val email = readln()
println("Введите имя")
val firstName = readln()
println("Введите фамилию")
val lastName = readln()
val id = userRepository.getAllUsers().count() + 1
val user = User(email = email, firstName = firstName, lastName = lastName, id = id)
userRepository.addUser(user)
}

6
src/data/models/User.kt Normal file
View File

@ -0,0 +1,6 @@
package data.models
data class User(val id: Int,
val firstName: String,
val lastName: String,
val email:String)

View File

@ -0,0 +1,10 @@
package data.repository
import data.models.User
interface UserRepository {
fun getAllUsers(): List<User>
fun addUser(user: User): Boolean
fun removeUserById(id: Int): Boolean
fun updateUser(id:Int, newUser: User): Boolean
}

View File

@ -0,0 +1,28 @@
package data.repository
import data.models.User
class UserRepositoryImpl : UserRepository {
private val _users = mutableListOf<User>(
User(id = 1, lastName = "Ivanov", firstName = "Ivan", email = "ivan@mai.ru"),
User(id = 2, lastName = "Petrov", firstName = "Petr", email = "petr@mai.ru"),
User(id = 3, lastName = "Alex", firstName = "Alexandrov", email = "Alex@mai.ru"),
User(id = 4, lastName = "Kolya", firstName = "Nikolaev", email = "kolya@mai.ru"),
)
override fun getAllUsers(): List<User> {
return _users
}
override fun addUser(user: User): Boolean {
val result = _users.add(user)
return result
}
override fun removeUserById(id: Int): Boolean {
TODO("Not yet implemented")
}
override fun updateUser(id: Int, newUser: User): Boolean {
TODO("Not yet implemented")
}
}