From 3553e1a873be2c972d8bf85e7f5834fb3f13f7b3 Mon Sep 17 00:00:00 2001 From: Zainab 27 Date: Sun, 16 Feb 2025 17:57:58 +0300 Subject: [PATCH 1/3] Part 1 --- ClassesTask/ClassesTask.iml | 15 +++++++++++++++ ClassesTask/src/WithoutConstructor.kt | 11 +++++++++++ 2 files changed, 26 insertions(+) create mode 100644 ClassesTask/ClassesTask.iml create mode 100644 ClassesTask/src/WithoutConstructor.kt 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/WithoutConstructor.kt b/ClassesTask/src/WithoutConstructor.kt new file mode 100644 index 0000000..6107bbf --- /dev/null +++ b/ClassesTask/src/WithoutConstructor.kt @@ -0,0 +1,11 @@ +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 +} \ No newline at end of file From fdb34974827824a76d49ded502e60ba40dafd611 Mon Sep 17 00:00:00 2001 From: Zainab 27 Date: Sun, 16 Feb 2025 18:40:09 +0300 Subject: [PATCH 2/3] All 3 parts of the classes exercise --- ClassesTask/src/WithoutConstructor.kt | 46 +++++++++++++++++++++------ 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/ClassesTask/src/WithoutConstructor.kt b/ClassesTask/src/WithoutConstructor.kt index 6107bbf..b55cfff 100644 --- a/ClassesTask/src/WithoutConstructor.kt +++ b/ClassesTask/src/WithoutConstructor.kt @@ -1,11 +1,37 @@ -class Book { - var title: String = "" - var author: String = "" - var yearPublished: Int = 0 +class Book(val title: String, val author: String, val yearPublished: Int) { + fun getBookInfo(): String { + return "$title by $author ($yearPublished)" + } } -fun main (){ - var newBook =Book() - newBook.title = "To kill a mockingbird" - newBook.author = "Harper Lee" - newBook.yearPublished = 1960 -} \ No newline at end of file + +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() +//} + From c63752e6bba8d188e1204fb730b8b5e4763ea70d Mon Sep 17 00:00:00 2001 From: Zainab 27 Date: Sun, 16 Feb 2025 18:41:45 +0300 Subject: [PATCH 3/3] 3 parts classes --- ClassesTask/src/Main.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 ClassesTask/src/Main.kt 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