Fabric manufacture

Report a typo

Let’s build a virtual factory that produces patterned fabric of various colors. To do that, write a secondary constructor of the given class Fabric. The secondary constructor should take color, pattern, and patternColor as arguments and set the corresponding property values. Then, print the updated information about the fabric.

The complete process of creating an object of the Fabric class should be as follows:

  1. Plain fabric is produced, and the message <color> fabric is created is output, with the corresponding argument value for <color>.
  2. Some color pattern is applied to the fabric. The message <patternColor> <pattern> pattern is printed on the fabric is shown, with the appropriate values for <pattern> and <patternColor>.

For example, creating a new object val fabric = Fabric("white", "dots", "black") is accompanied by the following output:

white fabric is created
black dots pattern is printed on the fabric

Hint: don't forget to set property values in the secondary constructor.

Write a program in Kotlin
class Fabric(var color: String) {
var pattern: String = "none"
var patternColor: String = "none"
init {
println("$color fabric is created")
}

constructor() {
}
}
___

Create a free account to access the full topic