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...
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...
Write  the following functions using the following structure for a point. struct Point { double x, y;...
Write  the following functions using the following structure for a point. struct Point { double x, y; }; (a) A function that passes a point and returns an integer (1, 2, 3, or 4) to indicate in which quadrant the point is located int findQuadrant(struct Point testpoint) { } (b) A function that passes two points and returns the distance between them. float distance(struct Point point1, struct Point point2) { } (c) A function that passes two points and generate the...
Please write python code for the following. Implement the functions defined below. Include a triple-quoted comments...
Please write python code for the following. Implement the functions defined below. Include a triple-quoted comments string at the bottom displaying your output. Using sets (described in Deitel chapter 6) will simplify your work. Below is the starter template for the code: def overlap(user1, user2, interests): """ Return the number of interests that user1 and user2 have in common """ return 0    def most_similar(user, interests): """ Determine the name of user who is most similar to the input user...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT