Answer to Question #212243 in Java | JSP | JSF for nimra

Question #212243

  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



1
Expert's answer
2021-07-01T01:11:35-0400
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());
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS