0% found this document useful (0 votes)
2 views4 pages

Java Assignment Module 1 Part1

The document contains four Java programs that perform specific calculations. Program 1.1 converts Fahrenheit to Celsius, Program 1.2 computes the perimeter of a rectangle, Program 1.3 calculates kinetic energy, and Program 1.4 determines the distance between two points. Each program includes example values and prints the results to the console.

Uploaded by

opsamir9090
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)
2 views4 pages

Java Assignment Module 1 Part1

The document contains four Java programs that perform specific calculations. Program 1.1 converts Fahrenheit to Celsius, Program 1.2 computes the perimeter of a rectangle, Program 1.3 calculates kinetic energy, and Program 1.4 determines the distance between two points. Each program includes example values and prints the results to the console.

Uploaded by

opsamir9090
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/ 4

PROGRAM No.1.

Question: Write a program to convert temperature from Fahrenheit to Celsius. Accept the

Fahrenheit value as a parameter.

public class FahrenheitToCelsius {


public static double convertFahrenheitToCelsius(double fahrenheit) {
return (fahrenheit - 32) * 5 / 9;
}
public static void main(String[] args) {
double fahrenheit = 98.6; // Example Fahrenheit value
System.out.println(fahrenheit + " Fahrenheit = " +
convertFahrenheitToCelsius(fahrenheit) + " Celsius");
}
}
PROGRAM No.1.2

Question: Write a program to compute the perimeter of a rectangle. Accept length and

width as parameters.

public class RectanglePerimeter {


public static double computePerimeter(double length, double width) {
return 2 * (length + width);
}
public static void main(String[] args) {
double length = 5.0; // Example length
double width = 3.0; // Example width
System.out.println("Perimeter of the rectangle: " + computePerimeter(length,
width));
}
}
PROGRAM No.1.3

Question: Write a program to calculate kinetic energy. Accept mass (kg) and velocity

(m/s) as parameters.

public class KineticEnergy {


public static double computeKineticEnergy(double mass, double velocity) {
return 0.5 * mass * velocity * velocity;
}
public static void main(String[] args) {
double mass = 10.0; // Example mass in kg
double velocity = 5.0; // Example velocity in m/s
System.out.println("Kinetic Energy: " + computeKineticEnergy(mass, velocity) + "
Joules");
}
}
PROGRAM No.1.4

Question: Write a program to calculate the distance between two points (x1, y1) and (x2,

y2). Accept coordinates as parameters.

public class DistanceBetweenPoints {


public static double computeDistance(double x1, double y1, double x2, double y2) {
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
}
public static void main(String[] args) {
double x1 = 1.0, y1 = 2.0, x2 = 4.0, y2 = 6.0; // Example coordinates
System.out.println("Distance: " + computeDistance(x1, y1, x2, y2));
}
}

You might also like