Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mathCalc;
- public class MathCalc {
- //Custom function
- public static void Volcalc(double _radius) {
- double volume = 4.0 / 3.0 * Math.PI * _radius * _radius * _radius;
- say("The vloume of the sphere of radius"+_radius+" is "+volume);
- }
- /*calcVolCyl
- * calculate the volume of a cylinder based on
- * height and radius
- */
- static void CalcVolCyl(double radius, double height) {
- double volume = Math.PI * radius * radius * height;
- //decide if the Vol is bigger enough to be a pool
- if ((volume > 5) && (height <= 1.5)) {
- //only runs if the condition above is true
- say("The volume of your pool is "+volume);
- }
- else if ((volume > 0.1) && (height <= 0.3)) {
- //only runs if the condition above is true
- say("The volume of your bucket is "+volume);
- }
- else if ((volume >= 50) && (volume <= 1000)) {
- //only checks if the other conditions are not true
- say("The volume of your cystern is "+volume);
- }
- else {
- //The default case, If nothing else is true
- say("The volume of your whatever is "+volume);
- }
- }
- /*say function
- * The say function will output a string msg to the console
- *
- */
- public static void say(String msg) {
- System.out.println(msg);
- }
- public static void main(String[] args) {
- double radius = 0.5;
- double height = 0.2;
- //Volcalc(radius);
- CalcVolCyl(radius , height);
- height++;
- CalcVolCyl(radius , height);
- CalcVolCyl(500, height + 2.7);
- CalcVolCyl(4, 1.3);
- CalcVolCyl(2, 1.5);
- }
- }
Add Comment
Please, Sign In to add comment