diff --git a/ClassesTask/ClassesTask.iml b/ClassesTask/ClassesTask.iml new file mode 100644 index 0000000..4fd7bdb --- /dev/null +++ b/ClassesTask/ClassesTask.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ClassesTask/src/Main.kt b/ClassesTask/src/Main.kt new file mode 100644 index 0000000..7265465 --- /dev/null +++ b/ClassesTask/src/Main.kt @@ -0,0 +1,14 @@ +//TIP To Run code, press or +// click the icon in the gutter. +fun main() { + val name = "Kotlin" + //TIP Press with your caret at the highlighted text + // to see how IntelliJ IDEA suggests fixing it. + println("Hello, " + name + "!") + + for (i in 1..5) { + //TIP Press to start debugging your code. We have set one breakpoint + // for you, but you can always add more by pressing . + println("i = $i") + } +} \ No newline at end of file diff --git a/ClassesTask/src/WithoutConstructor.kt b/ClassesTask/src/WithoutConstructor.kt new file mode 100644 index 0000000..b55cfff --- /dev/null +++ b/ClassesTask/src/WithoutConstructor.kt @@ -0,0 +1,37 @@ +class Book(val title: String, val author: String, val yearPublished: Int) { + fun getBookInfo(): String { + return "$title by $author ($yearPublished)" + } +} + +fun main() { + val newBook = Book("To Kill a Mockingbird", "Harper Lee", 1960) + println(newBook.getBookInfo()) +} + + +//class Book { +// var title: String = "" +// var author: String = "" +// var yearPublished: Int = 0 +//} +//fun main (){ +// var newBook =Book() +// newBook.title = "To kill a mockingbird" +// newBook.author = "Harper Lee" +// newBook.yearPublished = 1960 +//} +// +//class Book(val title: String, val author: String, val yearPublished: Int) { +// fun printDetails() { +// println("Book Title: $title") +// println("Author: $author") +// println("Year Published: $yearPublished") +// } +//} +// +//fun main() { +// val newBook = Book("To Kill a Mockingbird", "Harper Lee", 1960) +// newBook.printDetails() +//} +