Question 01

Write a Dart program that defines a class ‘Rectangle’. The class should have the following characteristics:

  • Properties: Two properties, ‘length’ and ‘width’.

  • Constructor: A constructor that initializes the properties ‘length’ and ‘width’.

  • Area method: A method ‘area()’ that calculates the area of the rectangle.

  • Perimeter method: A method ‘perimeter() that calculates the perimeter of the rectangle.

  • Main function: In the main function, create an instance of the ‘Rectangle’ class with specific dimensions, and print the area and perimeter.

Question 02

Write a Dart program that defines a class ‘Student’. The class should have the following characteristics:

  • Properties: Three properties: ‘name’, ‘age’, and ‘grades’ (a list of integers).

  • Constructor: A constructor that initializes the ‘name’, ‘age’, and ‘grades’.

  • Average grade method: A method ‘averageGrade()’ that calculates and returns the average of the student’s grades.

  • Main function: In the main function, create an instance of the ‘Student’‘ class and print the student’s name, age, and average grade.

Question 03

Write a Dart program that defines a class ‘BankAccount’ with the following characteristics:

  • Properties: Two properties, ‘accountNumber’ and ‘balance’.

  • Constructor: A constructor that initializes the ‘accountNumber’ and ‘balance‘.

  • Deposit method: A method ‘deposit(double amount)’ that adds the specified amount to the balance.

  • Withdraw method: A method ‘withdraw(double amount)’ that subtracts the specified amount from the balance if there are sufficient funds. If the amount exceeds the balance, display an error message.

  • Main function: In the main function, create an instance of the ‘BankAccount‘ class, make a deposit, make a withdrawal, and print the final balance.

Question 04

Write a Dart program that defines a class ‘Library’ to manage a collection of books. Each book is represented by a ‘Book’ class, which should contain the following properties:

  • Properties:

    • ‘title’: The title of the book.

    • ‘author’: The author of the book.

    • ‘isbn’: The ISBN number of the book.

  • The ‘Library‘ class should have a list ‘books‘ and the following methods:

    • ‘addBook(Book book)’: Adds a book to the library’s collection.

    • ‘removeBook(String isbn)’: Removes a book from the collection based on the ISBN.

    • ‘findBookByTitle(String title)’: Searches for a book by its title and returns the book details.

    • ‘listBooks()’: Lists all books in the library.

  • In the ‘main()’ function, create a library, add several books, remove one, search for a book by title, and list all books.

Last modified: Tuesday, 3 December 2024, 3:39 AM