0% found this document useful (0 votes)
4 views3 pages

Lab Sheet 5 - Methods

The document outlines a lab sheet for CMP 120130 focusing on object-oriented programming in Java. It includes tasks for creating static and non-static methods for mathematical calculations, a simple bank account system, and geometric calculations, as well as methods for computing averages, interest, and grades based on user input. Additionally, it provides guidelines for implementing a menu-driven program for user interaction and specific output formatting.

Uploaded by

nkphysics29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Lab Sheet 5 - Methods

The document outlines a lab sheet for CMP 120130 focusing on object-oriented programming in Java. It includes tasks for creating static and non-static methods for mathematical calculations, a simple bank account system, and geometric calculations, as well as methods for computing averages, interest, and grades based on user input. Additionally, it provides guidelines for implementing a menu-driven program for user interaction and specific output formatting.

Uploaded by

nkphysics29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CMP 120130 Object Oriented Modeling and Development

Lab sheet 5
Methods
PART A
1. Write a static method that calculates the square number of an integer and displays the
answer.
2. Write a static method that takes a Celsius value as a parameter. Then calculate and display
the Fahrenheit value of the Celsius value.
3. Write a static method that takes weight (kg) and height (m) as parameters and returns BMI
value.
4. Write non-static methods for question 1, 2 and 3.
5. Design a Java program for a simple bank account system. The class should have methods to
perform the following operations:
• Deposit:
o Create a method that allows a user to deposit a specified amount into the account.
o The method should update the account balance accordingly.
• Withdraw:
o Implement a method that enables a user to withdraw a specified amount from the
account.
o Ensure that the withdrawal does not exceed the available balance.
• Check Balance:
o Develop a method to print the current balance of the account.
6. Create a menu-driven Java program that allows the user to perform various geometric calculations.
Include the following options:
a. Calculate Area of a Circle:
a. Prompt the user for the radius, calculate and display the calculated area.
b. Calculate Area of a Rectangle:
a. Prompt the user for the length and width of a rectangle, calculate and display the
calculated area.
c. Calculate Area of a Triangle:
a. Take the base and height of a triangle as input, calculate and display the calculated area.
d. Exit:
o Allow the user to exit the program.

Implement a function for option a, b and c. Also, a function for displaying the menu to the user. Using the
functions implemented complete the program.
PART B
1. Write non-static methods to do the following tasks. According to the task explained
identify return type, passing parameters of the methods.
a. To compute and display an average of three numbers that are passed to the
method.
b. To compute and return the annual interest amount when annual interest rate is
4.3% and deposit amount is Rs. 500,000.00.
c. To display the item name, quantity, unit price and total price when they are passed
to the method.
d. To print the relevant weight status when the BMI value is passed to the method.
Refer the table below for the BMI value ranges and the corresponding weight
status.

BMI value range Weight status


Below 18.5 (exclusive) Underweight
18.5 – 24.9 (exclusive) Healthy Weight
24.9 – 29.9 (exclusive) Overweight
30.0 and Above Obesity

2. Consider the following statement below.


“Nimal needs a program that displays the corresponding grade for a subject when a
student has entered his/her subject mark.”.
Identify the tasks in this statement. Implement methods for the identified tasks and develop a
complete program to satisfy the requirements in the statement.
Program output needs to be displayed as in the example below.
=======================================
Find your grade
Enter your subject mark: 80
Your grade for the subject is A.
========================================
Refer the table below for range of the mark and the corresponding grade.
Marks Grade
91-100 A+
81-90 A
71-80 B+
61-70 B-
51-60 C+
41-50 C-
<=40 Fail

You might also like