Surface Area and Volume of a Right Regular Octagonal Prism A right regular octag
ID: 3821872 • Letter: S
Question
Surface Area and Volume of a Right Regular Octagonal Prism
A right regular octagonal prism is a geometric figure with octagons at its top and base (shown below)
The surface area and volume of this type of prism are:
where a represents the base edge and h represents the height.
Write a class called OctPrism that contains the necessary information for storing and calculating the surface area and volume of a octagonal prism. In particular, the class should have:
members to store the base and height data
a constructor that accepts no parameters that initializes base and height to 0.0
mutators for the base and height
accessors for the base, height, area, and volume
Write a program that demonstrates the OctPrism class by:
creating an OctPrism object
asking the user for the base and height of the prism
reporting the base, height, area and volume
the base and height should be referenced in the output by using the appropriate accessors
The area and volume results should be set to 4 decimal places
Samples of the output are shown below:
Sample Output 1:
Enter the base edge of an Octagonal Prism: 5
Enter the height of an Octagonal Prism: 7
Given an octagonal prism with a base edge of 5.0 units, and height of 7.0 units:
The area is: 521.4214 units squared.
The volume is: 844.9747 units cubed.
Sample Output 2:
Enter the base edge of an Octagonal Prism: 10
Enter the height of an Octagonal Prism: 3
Given an octagonal prism with a base edge of 10.0 units, and height of 3.0 units:
The area is: 1205.6854 units squared.
The volume is: 1448.5281 units cubed.
Explanation / Answer
import java.util.scanner;
class OctPrism
{
public static void main (String args[])
{
scanner s = new Scanner(system.in);
System.out.println("Enter the base edge of an octagonal Prosm:");
double base=s.nextDouble();
System.out.println("Enter the height of an Octagonal Prism:");
double height= s.nextDouble();
OctPrism()
{
bsae=0.0;
height=0.0;
}
System.out.println("Given an octagonal prism with base edge of"+base+"units,and height of" +height+"units");
OctPrism op1= new OctPrism ();
op1.area();
op1.volume();
}
void area()
{
double area=(2*(2*base*height))+(8*base*height);
System.out.println("the area is:" +area+"unit squared");
}
void volume()
{ double vol= 2*area*height;
System.out.println("The volume is:"+vol+"units cubed");
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.