Ad

Encapsulation Practice


Course: Object Oriented Programming
Lab 04
Encapsulation

Task 1: Write a class Circle, which will model the functionality of a Circle.
  1. Attributes
}  radius
  1. Methods
}  Setter function for radius
}  Getter function for radius
}  To compute area
}  To compute perimeter
Note: For value of pi, use Math.PI
Expected Output:



Task 2: Make a Rectangle class that has color, width and height attribute. Color is of String type, while other two are int type attribute. All the attributes should be private and exposed via setter/getter methods. Define a method inside Rectangle class: int calculateArea() that returns area of Rectangle. Define another method in Rectangle class: int calculatePerimeter() that returns perimeter of rectangle. Make a RectangleTest class, in main method, instantiate a rectangle object, sets its width and height, and prints its area and perimeter.

Task 3: Create GardeBook class that contains instructorName and courseTitle private attributes. Define getter and setter methods for both attributes, and another method named void displayGradeBookInfo(). When this method is called, it should print courseTitle and instructorName.
Make another class named GardeBookTest, in its main method, instantiate GradeBook object and call displayGradeBookInfo() method.
Note: Class variables should be write-only.

Expected Output:



Task 4: Write a class BankAccount, which have following attributes:
  1. Attributes
}  accountNumber
}  accountTile
Both attributes are private.
Create a test class named BankAccountTest. In main method, instantiate BankAccount object and display information of account.
Note: Class variables should be read-only.
Expected Output:



                

Post a Comment

0 Comments