Question

In: Computer Science

Write the following functions. Each function needs function comments that describes function and its parameters double...

Write the following functions. Each function needs function comments that describes function and its parameters double sphereVolume( double radius) double sphereSuface( double radius) double cylinderVolume( double radius, double height) double coneSurface( double radius, double height) double coneVolume( double radius, double height) That computes the volume and surface of the sphere with radius, a cylinder with a circular base with radius radius , and height height , and a cone with a circular base with radius radius , and height height . Then write a test program to prompt user to enter values of radius and height, call six functions and display the results.

Solutions

Expert Solution

Solution

Code

import java.util.*;
public class Main {

public static void main(String[] args) {
  
double radius,height;
Scanner sc = new Scanner(System.in);

System.out.print("Enter the value of radius: ");
radius = sc.nextDouble();

System.out.print("Enter the value of: ");
height = sc.nextDouble();
sphereVolume(radius , height);
sphereSurface(radius , height);
cylinderVolume(radius , height);
cylinderSurface(radius , height);
coneVolume(radius , height);
coneSurface(radius , height);
output(radius , height);
}

public static double sphereVolume(double radius, double height) {
double volume = (4 / 3) * Math.PI * Math.pow(radius, 3.0);
return volume;
}

public static double sphereSurface(double radius, double height) {
double surface = 4 * Math.PI * Math.pow(radius, 2.0);
return surface;
}

public static double cylinderVolume(double radius, double height) {
double volume = Math.PI * Math.pow(radius, 2.0) * height;
return volume;
}

public static double cylinderSurface(double radius, double height) {
double surface = 2 * Math.PI * radius * height + 2 * Math.PI * Math.pow(radius, 2.0);
return surface;
}

public static double coneVolume(double radius, double height) {
double volume = (1.0 / 3.0) * Math.PI * Math.pow(radius, 2.0) * height;
return volume;
}

public static double coneSurface(double radius, double height) {
double surface = Math.PI * radius * (radius + Math.pow(( Math.pow(radius, 2.0) + Math.pow(height, 2.0)), .5));
return surface;
}

public static void output(double radius, double height) {
System.out.printf("Volume of sphere: %.2f\n", sphereVolume(radius , height));
System.out.printf("Surface area of Sphere: %.2f\n", sphereSurface(radius , height));
System.out.printf("Volume of cylinder: %.2f\n", cylinderVolume(radius , height));
System.out.printf("Surface area of cylinder: %.2f\n", cylinderSurface(radius , height));
System.out.printf("Volume of cone: %.2f\n", coneVolume(radius , height));
System.out.printf("Surface area of cone: %.2f\n", coneSurface(radius , height));
}
}

Screenshot

Output

---

all the best


Related Solutions

2-page double spaced document that describes how each page is supposed to function and its purpose to the website.
1. 2-page double spaced document that describes how each page is supposed to function and its purpose to the website. This document should include a list of some characteristics, features, and/or requirements.   2. Website map or hierarchical chart mapping out the different pages of your website. Use WORD (Insert – Illustrations – SmartArt feature) to create the map or chart.   3. Develop the planned design into an actual website. Your website should contain at least the minimum number...
Implement each of the following functions and write a basic main() function that tests each. For...
Implement each of the following functions and write a basic main() function that tests each. For convenience, you should be able to find this starter class under Mimir's assignment 4 starter code. Do not change the name, parameters, or returns of any of these functions or of the name of the class itself. There is also no need in this assignment for any global variables. You are strongly encouraged to use your solution for some of these functions in others...
Write a Racket function "combine" that takes two functions, f and g, as parameters and evaluates...
Write a Racket function "combine" that takes two functions, f and g, as parameters and evaluates to a new function. Both f and g will be functions that take one parameter and evaluate to some result. The returned function should be the composition of the two functions with f applied first and g applied to f's result. For example (combine add1 sub1) should evaluate to a function equivalent to (define (h x) (sub1 (add1 x))). You will need to use...
C++ Write the implementation of the function concatenateIntArrays. This function receives 4 parameters in the following...
C++ Write the implementation of the function concatenateIntArrays. This function receives 4 parameters in the following order: An array of integer values (array1). An integer representing the size of array1 (size1). An array of integer values (array2). An integer representing the size of array2 (size). The function creates a dynamic array of integers of size size1+size2 to store all the values in array1, followed by all the values in array2. The function returns the pointer used to create the dynamic...
Write a function called printChList that takes as its parameters a character array, its size, and...
Write a function called printChList that takes as its parameters a character array, its size, and output file stream. The function should print the contents of the array to the output file. code with c++ and detail explaination
Assignment Write each of the following functions. The function header must be implemented exactly as specified....
Assignment Write each of the following functions. The function header must be implemented exactly as specified. Write a main function that tests each of your functions. Specifics In the main function ask for a filename and fill a list with the values from the file. Each file should have one numeric value per line. This has been done numerous times in class. You can create the data file using a text editor or the example given in class – do...
Write a C++ function, smallestIndex, that takes as parameters an int array and its size and...
Write a C++ function, smallestIndex, that takes as parameters an int array and its size and returns the index of the first occurrence of the smallest element in the array. Write another C++ function,lastLargestIndex, that takes as parameters an int array and its size and returns the index of the last occurrence of the largest element in the array. An analysis and design of the function smallestIndex is given below. Write an analysis and design for the function lastLargestIndex. Write...
Write a C++ function, smallestIndex, that takes as parameters an int array and its size and...
Write a C++ function, smallestIndex, that takes as parameters an int array and its size and returns the index of the first occurrence of the smallest element in the array. Also, write a program to test your function. You must write our commands in the middle: Write a C++ Program: #include <iostream> using namespace std; const int ARRAY_SIZE = 15; void printArray(const int x[], int sizeX); int smallestIndex(const int x[], int sizeX); int main() {      int list[ARRAY_SIZE] = {56,...
Write a program that contains the following Write a function copies with two int parameters, named...
Write a program that contains the following Write a function copies with two int parameters, named n and x. It should dynamically allocate a new array of size n.  The function should then copy the value in x to every position in the array. The function should return a pointer to the new array. In the main function, call the copies function from part 1. with size 5 and value -1.  Output the resulting array to the screen, and deallocate the array....
Write a C++ function which takes an int array and its size as parameters. It returns...
Write a C++ function which takes an int array and its size as parameters. It returns an int indicating how many multiples of 3 are contained in the array. For example, if the array contains {2, 6, 8} your function should return 1. If the array contains {3, 10, 5, 6} your function should return 2. Here is the function prototype: // int array[]: array to search // size: number of elements in the array int countMult(const int array[], int...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT