Question

write the following methods and provide a program to test them. double average(double x, double y,...

write the following methods and provide a program to test them.

double average(double x, double y, double z), returning the average of the arguments.

in java 1.7

Homework Answers

Answer #1
import java.util.Scanner;

public class AverageThree {

    public static double average(double x, double y, double z) {
        return (x + y + z) / 3.0;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter three numbers: ");
        double x = in.nextDouble();
        double y = in.nextDouble();
        double z = in.nextDouble();
        System.out.println("Average of three numbers is " + average(x, y, z));
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write the following functions and provide a program to test them (main and all functions in...
Write the following functions and provide a program to test them (main and all functions in one .py). 6 pts def allTheSame(x, y, z) (returning true if the arguments are all the same) def allDifferent(x, y, z) (returning true if the arguments are all different) def sorted(x, y, z) (returning true if the arguments are sorted, smallest one first keep it simple, python
Write the following functions and provide a program to test them (main and all functions in...
Write the following functions and provide a program to test them (main and all functions in one .py). 5 pts def firstDigit(n) (returning the first digit of the argument) def lastDigit(n) (returning the last digit of the argument) def digits(n) (returning the number of digits of the argument) For example, firstDigit(1729) is 1, lastDigit(1729) is 9, and digits(1729) is 4. keep it simple python
Write a C++ program to compute the value of x * (x + 1) + y...
Write a C++ program to compute the value of x * (x + 1) + y * y + z * (z - 1) where x, y, and z are 3 floating point numbers entered by the user. Requirements: • You should have a function get3numbers() that asks the user to enter 3 numbers. • You should have a function computeExp() that computes the value of the expression. • Your main function should call the above 2 functions and get...
Write a program in Java called CatChoir. It assumes the availability of a class called Cat...
Write a program in Java called CatChoir. It assumes the availability of a class called Cat (do NOT write the Cat class, just assume it is available), and the two Cat methods purr and meow. The program creates 2 Cat objects and sends each of them a purr messages and two meow messages. Neither the constructor for Cat nor its methods require any arguments. The methods are void.
In java : Write a program that will provide important statistics for the grades in a...
In java : Write a program that will provide important statistics for the grades in a class. The program will utilize a for-loop to read ten floating-point grades from user input. Include code to prevent an endless loop. Ask the user to enter the values, then print the following data: Average Maximum Minimum
Write a program to check the location of a point (x, y) in a 2D coordinate...
Write a program to check the location of a point (x, y) in a 2D coordinate system and display message differently: point (x, y) is on the original point; or is on the x-axle; or on the y-axle; or in one of 4 quadrants. When the point (x, y) is in a quadrant, the message should include quadrant information. For example, point (3, 5) is in quadrant I. In Java Please
Design, code, and test a program that includes a function of type double called divbaby that...
Design, code, and test a program that includes a function of type double called divbaby that accepts two double arguments (you must write the divbaby function). When called, your function will return the first argument divided by the second argument. Make sure your function includes a decision statement so that it can't divide by 0--if the caller attempts to divide by 0 the function should return a value of -2.0. Your program should call divbaby then display the value returned...
Write a Java program to print the result of the following operations. Your program should contain...
Write a Java program to print the result of the following operations. Your program should contain 4 methods (for each of given data sets). Yes, methods here are not structurally necessary, this requirement is only for you to get practice writing methods. Test Data: a. -8 + 4.0 * 6 b. (11+9) % 9 c. 20 + (-3)*3.0 / 8 d. 5 + 14 / 3 * 2 - 7 % 3 Your program:
IN JAVA Complete the following program. Add codes in the main method to:1) call method average(double[]...
IN JAVA Complete the following program. Add codes in the main method to:1) call method average(double[] gpaarr ) to calculate the average of gpaArray; 2) add codes in the for loop to calculate sum 3) print the average . public class Test { public static void main (String args[]) { double[ ] gpaArray = { 2.5, 4.0, 3.8, 3.2, 2.9, 4.0 } ;   //add your codes here (you can put your codes in the Answer area with/without copying the original...
write a simple verilog program on vivado/xilinx to find the average(mean) of numbers. Also provide the...
write a simple verilog program on vivado/xilinx to find the average(mean) of numbers. Also provide the test bench.