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

Lab 02 - Classes, Objects, Methods, User Input

This document outlines 4 tasks for an object-oriented programming lab. Task 1 involves creating a GradeBook class with a displayMessage method and calling it from another class. Task 2 creates a Circle class with radius and methods to calculate area and perimeter. Task 3 creates a Rectangle class with length, width, and methods to calculate area and perimeter. Task 4 creates a BankAccount class with balance and name attributes along with deposit and withdraw methods, and tests it in another class by getting user input.

Uploaded by

DJ A.H
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Lab 02 - Classes, Objects, Methods, User Input

This document outlines 4 tasks for an object-oriented programming lab. Task 1 involves creating a GradeBook class with a displayMessage method and calling it from another class. Task 2 creates a Circle class with radius and methods to calculate area and perimeter. Task 3 creates a Rectangle class with length, width, and methods to calculate area and perimeter. Task 4 creates a BankAccount class with balance and name attributes along with deposit and withdraw methods, and tests it in another class by getting user input.

Uploaded by

DJ A.H
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Course: Object Oriented Programming

Lab 02
Classes, Objects, Methods, User Input

Task 1: Write java code to create the GradeBook class that contains a displayMessage method
to displays a message on the screen. You will need to make an object of this class and call its
method to execute display the message.
Now declare a separate class that contains a main method. The GradeBookTest class declaration
will contain the main method that will control your application’s execution.
Expected Output:

Task 2: Write a class Circle, which will model the functionality of a Circle.
1. Attributes

 radius

2. Methods

 calculateArea(): To compute area

 calculatePerimeter(): To compute perimeter

Note: For value of pi, use Math.PI

Expected Output:

Task 3: Write a class Rectangle, which will model the functionality of a Rectangle.
1. Attributes

 Length

 Width

2. Methods
 calculateArea(): To compute area

 calculatePerimeter(): To compute perimeter

Expected Output:

Task 4: Make BankAccount class with balance and name attributes of type double and String.


Define public void deposit(double amount) and public void withdraw(double
amount) methods. Deposit should increase the balance by passed value and withdraw should
decrease the balance with passed amount.

Make BankAccountTest class. In main method, create a new object of BankAccount class. Get


balance and name of account holder from user input and initilize both object attributes. Then
show this menu:

Press 1: To Deposit an amount


Press 2: To Withdraw an amount
Press 3: To View the current balance

If user press 1: show following:


Enter the amount you want to desposit in your account >
For example. If user enters 500, call the desposit method of BankAccount object and pass 500 to
it. Do it for option 2 but call the withdraw method. If user choose 3 from menu, print the current
balance.

You might also like