Question

public static double[] getVolumes(double[] base, double[] height, double[] length) Write a Java program called TriangularPrisms which...

public static double[] getVolumes(double[] base, double[] height,
double[] length)
  1. Write a Java program called TriangularPrisms which does the following: In the main method:

    1. Use a for loop which repeats three times. Within the loop,
      a. prompt the user to enter the base of the triangular prism and store the value in a

      double array called base
      b. prompt the user to enter the corresponding height and store the value in a double

      array called height
      c. prompt the user to enter the corresponding length and store the value in a double

      array called length

    2. Call the method getVolumes with the following header and body:

    1. Within a for loop, calculate the volume of each triangular prism using the values stored in the arrays, and store the volume in a double array called volume.

    2. Return the volume array at the end of the method.

Submit the java and class files via Canvas (as a single zip-file). Include a comment block at the top of

each Java file that includes your name, student id number, and “Lab 4-Spring 2020”.

3. Back in the main method, use a for loop to display the volume of each of the three triangular prisms.

Bring the working TriangularPrisms.java and TriangularPrisms.class files to your lab session for pre-lab credit.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

class TriangularPrisms {
public static void main(String[] args) {

Scanner s= new Scanner(System.in);

//double type arrays(of size 3) of base, height, length
double[] base, length, height;
base= new double[3];
length= new double[3];
height= new double[3];

//A for loop which will repeat 3 times
for(int i=0; i<3; i++){
System.out.println("\nTriangular Prism number "+(i+1));
//Prompting the user for base, height and length of triangular prism
System.out.print("Enter the base of the triangular prism: ");
base[i]= s.nextDouble();

System.out.print("Enter the corresponding height: ");
height[i]= s.nextDouble();

System.out.print("Enter the corresponding length: ");
length[i]= s.nextDouble();
}
//A double type array for storing volumes
double[] volume;
volume=getVolumes(base,height,length);
//Now displaying volumes of each triangular prism
for(int i=0; i<3; i++){
System.out.println("\nVolume of triangular prism number "+(i+1)+": "+volume[i]);
}
}
//Method for calculating the Volume of triangular prism
public static double[] getVolumes(double[] base, double[] height, double[] length){
//As formula of calculating volume of triangular prisms is (1/2 * base * height *length)
double[] volume= new double[3];

for (int i=0; i<3; i++){
//calculating volume
volume[i]= (1.0/2.0) * base[i] * height[i] *length[i];
}
//returning the volume(calculated) array
return volume;
}
}

Comment down for any Queries......

Give a Thumbs Up if you like it!!

Add a comment
Know the answer?
Add Answer to:
public static double[] getVolumes(double[] base, double[] height, double[] length) Write a Java program called TriangularPrisms which...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a java method to calculate the area of a kite using the following formula: area...

    Write a java method to calculate the area of a kite using the following formula: area = (length x height ) /2 The method return a double value to main for the area and receives no parameters. public static double area () the method will prompt the user to enter a value for length and height, will calculate the area and then returns the value of area to main. Main will display this value to user.

  • Java programming: Write a program called Distribution that reads a file of double values into an...

    Java programming: Write a program called Distribution that reads a file of double values into an array and computes and prints the percentage of those numbers within 1 standard deviation (SD), within 2 SDs, and within 3 SDs of the mean. The program should be modular and should at least contain the main method and a method for computing the above percentages given the numbers, the mean, and the standard deviation. Other required statistics should be computed in their own...

  • 7.2 Write a Java program called to create an Excel spreadsheet Create a class called Food...

    7.2 Write a Java program called to create an Excel spreadsheet Create a class called Food to represent a Lunch food item. Fields include name, calories, carbs In a main method (of a different class), ask the user "How many things are you going to eat for lunch?". Loop through each food item and prompt the user to enter the name, calories, and grams of carbs for that food item. Create a Food object with this data, and store each...

  • JAVA Code Requried Copy the file java included below. This program will compile, but, when you...

    JAVA Code Requried Copy the file java included below. This program will compile, but, when you run it, it doesn’t appear to do anything except wait. That is because it is waiting for user input, but the user doesn’t have the menu to choose from yet. We will need to create this. Below the main method, but in the Geometry class, create a static method called printMenu that has no parameter list and does not return a value. It will...

  • This is for a java program public class Calculation {    public static void main(String[] args)...

    This is for a java program public class Calculation {    public static void main(String[] args) { int num; // the number to calculate the sum of squares double x; // the variable of height double v; // the variable of velocity double t; // the variable of time System.out.println("**************************"); System.out.println(" Task 1: Sum of Squares"); System.out.println("**************************"); //Step 1: Create a Scanner object    //Task 1. Write your code here //Print the prompt and ask the user to enter an...

  • java programe Write a program that prompts the user to enter in an integer number representing...

    java programe Write a program that prompts the user to enter in an integer number representing the number of elements in an integer array. Create the array and prompt the user to enter in values for each element using a for loop. When the array is full, display the following: The values in the array on a single line. The array with all of the elements reversed. The values from the array that have even numbered values. The values from...

  • Write a java program that computes the total surface area of a rectangular prism. There are...

    Write a java program that computes the total surface area of a rectangular prism. There are six sides, so the area of all six sides has to the summed to get the total area. The program should ask the user to enter the length (L), width (W) and the height )H) for the object in inches. Create a separate method from the main to calculate the area (name the method calcArea). The output of calcArea will return a double. Output;...

  • Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called...

    Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called hw1 Create a project called hw1 (make sure you select the “Use project folder as root for sources and class files”) Create a class called Hw1 in the hw1 package (make sure you check the box that auto creates the main method). Add a comment to the main that includes your name Write code that demonstrates the use of each of the following basic...

  • in java eclipse, Create a program “FibonacciFifteen.java” and a method called “double[] getFibonacci()” that creates an...

    in java eclipse, Create a program “FibonacciFifteen.java” and a method called “double[] getFibonacci()” that creates an array with a length of 15 that contains the first 15 numbers in the Fibonacci sequence and returns it. Set the first element to 0 and the second element to 1, then use a for loop to fill out the rest of the array by adding the prior two elements.

  • We are using blueJ for my java class, if you can help me id greatly appreciate...

    We are using blueJ for my java class, if you can help me id greatly appreciate it. Create a new Java project/class called ChangeUp. Create an empty int array of size 6. Create a method called populateArray that will pass an array, use random class to choose a random index and prompt the user to enter a value, store the value in the array. Create a method called printArray that prints the contents of the array using the for each...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT