Question

In: Computer Science

1) Write a functional program in Java that can calculate the volume and surface area of...

1) Write a functional program in Java that can calculate the volume and surface area of a sphere and a cube

2) Write a procedural program in Java that can calculate the volume and surface area of a sphere and a cube

3) Write an Object Oriented Program in Java that can find the volume and surface area of a sphere and cube

Solutions

Expert Solution

Procedural Program:

import java.util.*;

class Main {

public static void main(String[] args) {

double radius, side,SAsphere,VSphere,SAcube,Vcube;

Scanner sc=new Scanner(System.in);

System.out.println("Enter radius of sphere: ");

radius=sc.nextDouble();

System.out.println("Enter Side of cube: ");

side=sc.nextDouble();

SAsphere=3.14*4*radius*radius;

VSphere=(4/3)*3.14*radius*radius*radius;

SAcube=6*side*side;

Vcube=side*side*side;

System.out.println("Surface area of sphere is : "+SAsphere);

System.out.println("Volume of Sphere: "+VSphere);

System.out.println("Surface area of Cube is "+SAcube);

System.out.println("Volume of Cube: "+Vcube);

}

}

2)Functional Program:

import java.util.*;

class Main {

public static double volumeSphere(double radius){

return (4/3)*3.14*radius*radius*radius;

}

public static double SAsphere(double radius){

return 3.14*4*radius*radius;

}

public static double volumeCube(double side){

return side*side*side;

}

public static double SACube(double side){

return 6*side*side;

}

public static void main(String[] args) {

double radius, side,SAsphere,VSphere,SAcube,Vcube;

Scanner sc=new Scanner(System.in);

System.out.println("Enter radius of sphere: ");

radius=sc.nextDouble();

System.out.println("Enter Side of cube: ");

side=sc.nextDouble();

System.out.println("Surface area of sphere is : "+SAsphere(radius));

System.out.println("Volume of Sphere: "+volumeSphere(radius));

System.out.println("Surface area of Cube is "+SACube(side));

System.out.println("Volume of Cube: "+volumeCube(side));

}

}

3) Object Oriented:

import java.util.*;

class Calculation {

public static double volumeSphere(double radius){

return (4/3)*3.14*radius*radius*radius;

}

public static double SAsphere(double radius){

return 3.14*4*radius*radius;

}

public static double volumeCube(double side){

return side*side*side;

}

public static double SACube(double side){

return 6*side*side;

}

}

class Main{

public static void main(String[] args) {

Calculation cal=new Calculation();

double radius, side,SAsphere,VSphere,SAcube,Vcube;

Scanner sc=new Scanner(System.in);

System.out.println("Enter radius of sphere: ");

radius=sc.nextDouble();

System.out.println("Enter Side of cube: ");

side=sc.nextDouble();

System.out.println("Surface area of sphere is : "+cal.SAsphere(radius));

System.out.println("Volume of Sphere: "+cal.volumeSphere(radius));

System.out.println("Surface area of Cube is "+cal.SACube(side));

System.out.println("Volume of Cube: "+cal.volumeCube(side));

}

}

if you like the answer please provide a thumbs up.


Related Solutions

Write a C++ program to calculate the sphere volume and surface area. Provided that the sphere...
Write a C++ program to calculate the sphere volume and surface area. Provided that the sphere volume = and the sphere surface area = , where r is the radius. 1. Read r from the user using cin statement. 2. Calculate the volume (Vol) and the surface area (Area) of a sphere. 3. Print r, Vol, and Area in a suitable messages.
Part One: Write an interactive program to calculate the volume and surface area of a three-dimensional...
Part One: Write an interactive program to calculate the volume and surface area of a three-dimensional object. Use the following guidelines to write your program: Create a word problem that involves calculating the volume and surface area of a three-dimensional object. Choose one of the following: Cube: surface area 6 s2 , volume s3 Sphere: surface area 4πr2 , volume (4.0/3.0) π r3 Cylinder: surface area 2π r2 + 2 π r h, volume π r2 h Cone: surface area...
Write a program in C++ that solves this problem Calculate the area and volume of a...
Write a program in C++ that solves this problem Calculate the area and volume of a sphere problem. Inside a for loop, vary the radius from 10 to 40  with a step or increment of 5 and calculate the area and volume Your radius will be equal to your loop counter. All calculations should have 2 decimal places, but the radius should have zero decimal places and any number of 1,000 or more should have a comma. Print the radius, area,...
User the Scanner class for your input Write a java program to calculate the area of...
User the Scanner class for your input Write a java program to calculate the area of a rectangle. Rectangle Area is calculated by multiplying the length by the width   display the output as follow: Length =   Width = Area = Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
know the mathematical relationship between surface area and volume, and explain how surface to area volume...
know the mathematical relationship between surface area and volume, and explain how surface to area volume affects heat loss. Which can be smaller endotherms or ectotherms  
Writing a Java Code Requirements of the JAVA program: Your task is to calculate geometric area...
Writing a Java Code Requirements of the JAVA program: Your task is to calculate geometric area for 3 shapes(square, rectangle and circle). You need to build a menu that allows users to enter options. Possible options are 'S' for square, 'R' for rectangle and 'C' for circle. HINT: you can use switch statement to switch on string input Invalid input should throw a message for the user. Example: Invalid input, please try again Each options should ask users for relevant...
Write a program that reads the radius of a sphere and calculates it's volume and surface...
Write a program that reads the radius of a sphere and calculates it's volume and surface area. Format results to 4 decimal places. The radius=3.2 Your program should output volume and surface area.  Repeat same steps for program2, but this time use the following input values: a= ꟷ2.4 , b = 4.5 . Your program should output sum, Fun1, and Fun2. It's for C++
Parse string java code Write a recursive program that can calculate the value of a given...
Parse string java code Write a recursive program that can calculate the value of a given polynomial in a string, which is not more than the tenth order, for the given x. The polynomial will be given in the following format and should display the value of the polynomial for spaced-out x Using index of for -/+
Write a JavaScript function to calculate the surface area of a sphere. Input the radius using...
Write a JavaScript function to calculate the surface area of a sphere. Input the radius using a NumericUpDown. Have the function calculate the surface area and display it on your page. Label the inputs and the output on your page. Change the title to "Oh, Boy! JavaScript!". Put your name at the top in camelCase. Put your major at the bottom in camelCase.
1. Write a Java program that prompts the user to enter three integer numbers. Calculate and...
1. Write a Java program that prompts the user to enter three integer numbers. Calculate and print the average of the numbers. 2. Write a Java program that uses a for loop to print the odd numbers from 1 to 20. Print one number per line in the command line window. 3. Write a program which asks the user to input the size of potatoe fries she would like to purchase, and based on the size, it will tell her...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT