0% found this document useful (0 votes)
15 views

Lab Sheet 5

Uploaded by

devmith2005
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Lab Sheet 5

Uploaded by

devmith2005
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

ICT 1411 Object Oriented Programming

Lab sheet – Class and Objects


1. Define a class named Car with attributes: model (String), year (int). Write a default constructor
that initializes the model to "Unknown", and year to 0. Include getters, setters, and a toString
method.
2. Create a class named Person with the following attributes: name (String), age (int). Include a
parameterized constructor, getters, setters, and a toString method.
3. Create a class Rectangle with attributes length (double) and width (double). Write a
parameterized constructor to initialize these attributes. Include methods to calculate the area and
perimeter of the rectangle.
4. Design a class Book with attributes title (String), author (String), and price (double). Create a
default constructor that sets title and author to "Unknown" and price to 0.0. Include a method
displayInfo to print the book information.
5. Define a class Student with attributes name (String), rollNumber (String), and marks (double).
Write a parameterized constructor to initialize these attributes. Include methods to calculate the
grade (A, B, C, etc.) based on the marks.
6. Implement a class BankAccount with attributes accountNumber (String), balance (double), and
ownerName (String). Include a parameterized constructor, getters, setters, and methods to
deposit and withdraw money. Ensure that the balance cannot go below zero.
7. Create a class Product with attributes productId (String), productName (String), and price
(double). Write a default constructor and a parameterized constructor. Include a method to apply
a discount to the product price.

You might also like