Q:

Write a java class called TeachMath that performs the following formula f(x,y,z)=X+Y^5+√(Z^4*2)-7

0

Write a java class called TeachMath that performs the following formula 

f(x,y,z)=X+Y^5+√(Z^4*2)-7 

 

Where the values of these variables are assumed in advance (there’s no need for user’s input).

Your class should apply the following:

      • Declare a static short value for variable z which it is initialized to zero.
      • In the main methods (as show in the code excerpt below), you should call the following methods
      • Method FunMath with two integer-based arguments which calculates and returns the result as shown in the formula above, this function uses the static z value.
      • Method FunMath with three floating-point arguments which calculates and returns the result as shown in the formula above, this function uses the local z value.
      • Method Print which prints the results

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.lang.Math;

public class TeachMath{

	// declare a static short variable called z and initialize it to zero
	public static short z = 0;	
	public static void main(String[] arg){
		short xi = 5, yi=2;
	// call FunMath method for the variables above and then call the Print 
		double result = FunMath(xi,yi);
		print(result);

		System.out.println("----------------------");
		double x = 1.3 , y = 3.5 , z = 2.4;
	// call FunMath method for the variables above and the Print method in ONE line
		print(FunMath(x,y,z));
		
	} // end main method
	
	public static long FunMath(long x, long y){
	// Use only the methods from Math class to calculate the results of the given formula above with respect to the //return type of the  
	
	return (long) (x + Math.pow(y,5)+Math.sqrt(Math.pow(z,4)*2)-7);
	
	} //end method	

	public static double FunMath(double x, double y, double z){
	// Use only the methods from Math class to calculate the results of the given formula above with respect to the //return type of the 
	return (x + Math.pow(y,5)+Math.sqrt(Math.pow(z,4)*2)-7);			
} // end method
	
	public static void print(double result){
	// to print the results as shown in the output by using lower and upper approximation methods in Math class
	// use printf method with %.2f as a placeholder for printing the results after 
	System.out.printf("The lower approximation of f(x,y,z) result is %.2f %n", Math.floor(result));
	System.out.printf("The upper approximation of f(x,y,z) result is %.2f %n", Math.ceil(result)); 

	
	} // end method
} // end class

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now