Git Product home page Git Product logo

hw_week2_day1_definingclasses's Introduction

HW_Week2_Day1_DefiningClasses


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. ⚠️

Instructions 📋

Part I - Practice with Class Defining.


Write a class named 'Car' with with following features:

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:

Part II - Practice with Instance Constrcuting and Class Functions.


Write a class named Book using primary constructor with following features:

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

Part III - (Optional) Classes Challenge.


Write a class named 'Rectangle' with following features.

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

* * * * * * 
* * * * * * 
* * * * * * 
* * * * * * 
* * * * * * 
* * * * * * 

Learning Resources 📚

hw_week2_day1_definingclasses's People

Contributors

aalherz avatar waadalshammari avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.