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

Assignment (itp)

The document contains programming exercises focused on static methods, method overloading, and instance methods in Java. It includes code examples for calculating the area of a circle, the volume of a sphere, and the volume of a rectangular prism. The exercises demonstrate fundamental programming concepts for a BSIT student named Justine Roxas.

Uploaded by

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

Assignment (itp)

The document contains programming exercises focused on static methods, method overloading, and instance methods in Java. It includes code examples for calculating the area of a circle, the volume of a sphere, and the volume of a rectangular prism. The exercises demonstrate fundamental programming concepts for a BSIT student named Justine Roxas.

Uploaded by

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

INTERMEDIETE TO PROGRAMMING

Name: Soliman, Justine Roxas DATE: 02/01/2025

Section&Grade: BSIT – 1E

1. Static Method Excercise


public class Circle { //<-- project class name
//static method name "calculateCircleArea"
public static double calculateCircleArea(double radius) {
//I used Math.PI as a representation of π
return Math.PI * radius * radius; // this is the formula of "A = π * r^2".
}
public static void main(String[] args) {
double radius; // Value can be putted here. sample value (8.0)
double area = calculateCircleArea(radius = 8.0); //<-- Also the value of radius can be putted
here;
/*after calling the main method "calculateCircleArea"
and sample radius we can now print the result */
System.out.println("Area of the circle with radius " + radius + " is: " + area);
}
}
OUTPUT:

2.Overloading Exercise
public class Volume {
// Method to calculate the volume of a sphere
public static double volume(double radius) {
return (4.0 / 3.0) * Math.PI * Math.pow(radius, 3);
}
// Overloaded method to calculate the volume of a rectangular prism
public static double volume(double length, double width, double height) {
return length * width * height; // V = l * w * h
}
public static void main(String[] args) {
double sphereVolume = volume(3.0);
System.out.println("The Volume of sphere is: " + sphereVolume);
double prismVolume = volume(2, 3, 4);
System.out.println("The Volume of rectangular prism is: " + prismVolume);
}
}
INTERMEDIETE TO PROGRAMMING

OUTPUT CODE:

3. Instance Method Exercise:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy