Using jGRASP I need the code to run this program please!! Grading criteria: 80%
ID: 3821876 • Letter: U
Question
Using jGRASP I need the code to run this program please!!
Grading criteria:
80% - Functionality: Runs correctly, generating correct outputs. A program that does not compile will be heavily penalized.
10% - Style: Use consistent indentation to emphasize block structure; variables have meaningful names.
10% - Comments: Comment major code segments adequately.
---------------------------------------------------------------------------------------------------------
Please submit the following java programs in a single zipped folder on Canvas:
Octagonal Prism (60 pts) - OctPrism.java
Driver Program (40 pts) – OctDriver.java
Extra Credit: Square Table (10pts) – SquareTable.java
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.
Extra Credit: Square Table
Write a program that uses a two-dimensional array to store and display the following values in a 5 x 5 table:
1 2 3 4 5
4 8 12 16 20
9 18 27 36 45
16 32 48 64 80
25 50 75 100 125
Your program should generate (i.e. calculate) the numbers so that:
The first five numbers 1 – 5 are displayed in the first row
The square of the first 5 numbers are displayed in the first column
The remaining values are multiples of the values in the first row and column
(Your program should output the numbers in a neat format, but do not worry if the larger values are slightly out of alignment.
Explanation / Answer
OctPrism.java
/**
*
* Please submit the following java programs in a single zipped folder on Canvas:
Octagonal Prism (60 pts) - OctPrism.java
Driver Program (40 pts) – OctDriver.java
Extra Credit: Square Table (10pts) – SquareTable.java
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)
figure1.png
The surface area and volume of this type of prism are:
figure2.png
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.
*
*/
public class OctPrism {
private double base;
private double height;
// Calculate area
public double getArea()
{
double area = 8*base*height + 4*(1+Math.sqrt(2))*base*base;
return area;
}
// calculate volume
public double getVolume()
{
double volume = 2*(1+Math.sqrt(2))*base*base*height;
return volume;
}
// constructor
public OctPrism(double a, double h)
{
this.base = a;
this.height = h;
}
// no argument constructor
public OctPrism()
{
this(0.0, 0.0);
}
// mutator and accessors
public double getBase() {
return base;
}
public void setBase(double base) {
this.base = base;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
}
DriverOctPrism.java
import java.util.Scanner;
public class DriverOctPrism {
public static void main(String[] args)
{
// to get user input
Scanner sc = new Scanner(System.in);
// get base from user
System.out.print("Enter the base edge of an Octagonal Prism: ");
double base = sc.nextDouble();
// get height from user
System.out.print("Enter the height of an Octagonal Prism: ");
double height = sc.nextDouble();
// create octprism object
OctPrism octprism = new OctPrism();
// set base and height
octprism.setBase(base);
octprism.setHeight(height);
// calculate an print area and volume
System.out.printf("Given an octagonal prism with a base edge of %.1f units, and height of %.1f units: ", octprism.getBase(), octprism.getHeight());
System.out.printf("The area is: %.4f units squared. ", octprism.getArea());
System.out.printf("The volume is: %.4f units cubed. ", octprism.getVolume());
sc.close();
}
}
Sample output
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.
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.
Extra credit
SquareTable.java
public class SquareTable {
public static void main(String[] args) {
int[][] square = new int [5][5];
for(int i = 0; i < 5; i++)
{
square[i][0] = (i+1)*(i+1);
for(int j = 0; j < 5; j++)
{
square[i][j] = square[i][0]*(j+1);
}
}
for(int i = 0; i < 5; i++)
{
for(int j = 0; j < 5; j++)
{
System.out.print(square[i][j] + " ");
}
System.out.println();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.