The Homework has three components to be delievered before 9AM:
- Practice with Class Defining.
- Practice with Instance Constrcuting and Class Functions.
- (Optional) Classes Challenge.
Note: You must save all your solution as
solution.kt
to be submitted before 9AM.⚠️
Instance variables :
- model for the car model of type String.
- year for the car year of type int.
How it works:
- Create an instance of car
- Assign the values "Toyota" and "2020" to model and year variables respectively
- print the result
Output:
Instance variables :
- title for the title of book of type String.
- author for the author’s name of type String.
- price for the book price of type double.
Instance functions:
- bookDetails(): This method well take a inStock boolean value to check if the book in stock or not, and then print out book’s details to the screen
Output:
--- Book Details ---
Name: Game of Thrones
Author: George Martin
Price: $54.00
Availability: In stock
--- Book Details ---
Name: We Were Liars
Author: E. Lockhart
Price: $30.00
Availability: Out of stock
Instance variables :
- length for the length of rectangle of type int.
- width for the width of rectangle of type int.
Instance functions:
- 'getPer()' which return the perimeter of the rectangle.
- 'getArea()' which return the area of the rectangle.
- 'draw()' which draws rectangle by stars.
How it work:
- Ask user to input length and width for a rectangle.
- Print the result.
Output:
Please enter length: 6
Please enter width: 6
---------------
Rectangle perimeter is 24
Rectangle area is 36
* * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * *