Write a program using class ‘Math’ pass three values as arguments to the constructor of the class and initialize these values to data members x,y and z of the class. The class should have following member functions.
· maximum : return maximum number
· minimum : return minimum number
· sum : return the sum of three numbers
import java.lang.Math;
public class Maths {
private int x;
private int y;
private int z;
public Maths(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getZ() {
return z;
}
public void setZ(int z) {
this.z = z;
}
public int max() {
int max = Math.max(x, Math.max(y, z));
return max;
}
public int min() {
int min = Math.min(x, Math.min(y, z));
return min;
}
public int sum() {
int sum = x + y + z;
return sum;
}
public static void main(String[] args) {
Maths maths = new Maths(7, 63, 15);
System.out.println("Maximal value: " + maths.max());
System.out.println("Minimal value: " + maths.min());
System.out.println("Sum of values: " + maths.sum());
}
}
Comments
Leave a comment