This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Builder { | |
String firstName; | |
String lastName; | |
int age; | |
public Builder firstName(String firstName) { | |
this.firstName = firstName; | |
return this; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person { | |
final String firstName; | |
final String lastName; | |
final int age; | |
Person(String firstName, String lastName, int age) { | |
Objects.requireNonNull(firstName); | |
Objects.requireNonNull(lastName); | |
this.firstName = firstName; | |
this.lastName = lastName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun diameter(shape: Shape): Double = when (shape) { | |
is Rectangle -> Math.sqrt(shape.x * shape.x + shape.y * shape.y) | |
is Circle -> 2 * shape.radius | |
is Parallelogram -> /* Math */ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun area(shape: Shape): Double = when (shape) { | |
is Rectangle -> shape.x * shape.y | |
is Circle -> PI * shape.radius * shape.radius | |
is Parallelogram -> shape.side * shape.height | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun perimeter(shape: Shape): Double = when (shape) { | |
is Rectangle -> (shape.x + shape.y) * 2 | |
is Circle -> 2 * PI * shape.radius | |
is Parallelogram -> (shape.base + shape.side) * 2 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class Shape | |
class Rectangle(val x: Double, val y: Double) : Shape() | |
class Circle(val radius: Double) : Shape() | |
class Parallelogram(val base: Double, val height: Double): Shape() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun diameter(shape: Shape): Double = when (shape) { | |
is Rectangle -> Math.sqrt(shape.x * shape.x + shape.y * shape.y) | |
is Circle -> 2 * shape.radius | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun area(shape: Shape): Double = when (shape) { | |
is Rectangle -> shape.x * shape.y | |
is Circle -> PI * shape.radius * shape.radius | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun perimeter(shape: Shape): Double = when (shape) { | |
is Rectangle -> (shape.x + shape.y) * 2 | |
is Circle -> 2 * PI * shape.radius | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Shape {} | |
class Rectangle implements Shape { | |
double x, y; | |
} | |
class Circle implements Shape { | |
double radius; | |
} |
NewerOlder