1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Mariulka [41]
3 years ago
8

Define a method pyramidVolume with double parameters baseLength, baseWidth, and pyramidHeight, that returns as a double the volu

me of a pyramid with a rectangular base. Relevant geometry equations: Volume
Computers and Technology
1 answer:
marysya [2.9K]3 years ago
7 0
<h2>Question:</h2>

Define a method pyramidVolume with double parameters baseLength, baseWidth, and pyramidHeight, that returns as a double the volume of a pyramid with a rectangular base. Relevant geometry equations:

Volume = base area x height x 1/3

Base area = base length x base width.

(Watch out for integer division)

import java.util.Scanner;

public class CalcPyramidVolume {

   /* Your solution goes here */

   public static void main (String [] args) {

     System.out.println("Volume for 1.0, 1.0, 1.0 is: " + pyramidVolume(1.0, 1.0,   1.0));

     return;

    }

}

<h2>Answer:</h2><h2></h2>

import java.util.Scanner;

public class CalcPyramidVolume {

   /* Your solution goes here */

   public static void main (String [] args) {

       System.out.println("Volume for 1.0, 1.0, 1.0 is: " + pyramidVolume(1.0, 1.0, 1.0));

       return;

   }

   

   //Begin method definition

   public static double pyramidVolume(double baseLength, double baseWidth, double pyramidHeight){

       

       //First, calculate the base area of the pyramid

       //store the result in a double variable

       double baseArea = baseLength * baseWidth;

       

       //Then, calculate the volume of the pyramid

       //using the base area and the base width

       double volume = 1 / 3.0 * baseArea * pyramidHeight;

       

       //return the volume

      return volume;

   }

}

<h2>Output:</h2>

Volume for 1.0, 1.0, 1.0 is: 0.3333333333333333

<h2>Explanation:</h2>

The code above contains comments explaining the important lines of the code. The output of the code has also been provided above.

The parts of the code that are worth noting are:

(i) The return type of the method pyramidVolume should be a <em>double</em> since calculations are done using <em>double</em> values. i.e the method header should be written as

<em>public static double pyramidVolume(){</em>

<em>}</em>

<em />

(ii) The method requires three(3) parameters of type double: baseLength, baseWidth and pyramidHeight. These should be included in the method. Therefore, the complete header definition should be:

<em>public static double pyramidVolume(double baseLength, double baseWidth, double pyramidHeight){</em>

<em />

<em>}</em>

(iii) The formula for calculating the volume of the pyramid should be:

volume = 1 / 3.0 * baseArea * baseWidth;

Rather than;

volume = 1 / 3 * baseArea * baseWidth;

This is because integer division yields integer result. If 1 / 3 is evaluated, the result will be 0 since the decimal part will be truncated thereby making the result of the volume = 1 / 3 * baseArea * baseWidth will be 0.

Therefore, the work around for that should be to write 1 / 3.0 or 1.0 / 3.0 or 1.0 / 3.

(iv) After the calculation, the result of volume should be returned by the method. This will enable a proper call by the main method for execution.

You might be interested in
What is the meaning of N.W.O​
Likurg_2 [28]

Answer:

The New World Order (NWO) in conspiracy theories is the hypothesis of a secretly emerging totalitarian world government.

8 0
3 years ago
A(n) Answer display color uses the least electricity when compared to any other color.
Elan Coil [88]

Is there answer choices because I’m not understanding what you want me to answer

3 0
3 years ago
Can you please provide sample rexx code?
Aleks04 [339]

Answer:

/*  My first REXX program  */

say 'Hello world'

Explanation:

REXX is an OS/2 scripting language.

7 0
3 years ago
The internet is an example of
DochEvi [55]
A large multi user program
6 0
3 years ago
Read 2 more answers
Most shops require the technician to enter a starting and ending time on the repair order to track the actual time the vehicle w
Alecsey [184]

The time being referred to is C. cycle time. Cycle time refers to the amount of time from start to end of a process as agreed and defined by a service provider (in this case, the technician) and the customer. Cycle time can also be lengthened or shortened.

5 0
4 years ago
Read 2 more answers
Other questions:
  • How can you best utilize CSS for Web Development?
    6·1 answer
  • A user is claiming a host can be reached via the IP address but not through the name. What should a technician do first to resol
    13·1 answer
  • When an object is instantiated, it receives its own copy of all static variables of the class?
    14·1 answer
  • This function whose primary purpose is to display information to the user can only display one value at a time.
    15·1 answer
  • A computer byte is the amount of data (measured in bits) that CPU can manipulate at one time/
    8·1 answer
  • Date Class Constructor – assigns fields to appropriate formal parameter – using the setters so error checking will occur. The co
    6·1 answer
  • Richard needs to copy information from another slide presentation that uses a different design template. To ensure that the info
    10·1 answer
  • Which of the following characterizes how an enabled security program might react to a new program installation on a computer sys
    7·2 answers
  • . An operating system is: *
    14·1 answer
  • When you try to move the desktop icon using the click and drag method and it doesn't move, what is the reason?​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!