222k views
25 votes
Reading Materials Design and implement a set of classes that define various types of reading material: books, novels, magazines, technical journals, textbooks, and so on. Include data values that describe various attributes of the material, such as the number of pages and the names of the primary characters. Include methods that are named appropriately for each class and that print an appropriate message. Create a main driver class to instantiate and exercise several of the classes.

1 Answer

8 votes

Answer:

Answered below

Step-by-step explanation:

//The designs are implemented in Kotlin.

//Book class

class Book (val title: String,

val type: String,

val numberOfPages: Int,

val author: String ,

val yearPublished: Int ) {

fun bookDescription( ){

print("Book title is $title. Written

by $author and published

in $yearPublished" )

}

}

//Driver class

class Main {

fun main( ) {

val novel: Book = Book("Animal Farm", "novel", 200, "Orwell", 1990 )

println(novel.title)

println(novel.author)

val description = novel.bookDescription( )

println(description)

val magazine: Book = Book("Forbes", "magazine", 50, "Michael", 1995)

}

}

User Ocos
by
2.8k points