Question

In: Computer Science

Create a new Java project called lab1 and a class named Lab1 Create a second class...

  1. Create a new Java project called lab1 and a class named Lab1
  1. Create a second class called VolumeCalculator.

  1. Add a static field named PI which = 1415

  1. Add the following static methods:

  1. double static method named sphere that receives 1 double parameter (radius) and returns the volume of a sphere.

  1. double static method named cylinder that receives 2 double parameters (radius & height) and returns the volume of a cylinder.

  1. double static method named cube that receives 1 double parameter (side) and returns the volume of a cube.

  1. double static method named box that receives 3 double parameters (length, width & height) and returns the volume of the box

  1. Back in Lab1 in the main method,
    1. Declare variables for each of the values used as parameters for the above methods, and then give them values.

  1. Call each of the static methods in VolumeCalculator sending the appropriate variable in as a parameter.
    Print the value of the variable(s) sent and the result, with labels. (Also, tell me which shape this volume is for.)

Solutions

Expert Solution

import java.util.*;

public class volumeCalculator
{
  static double pi = (22.0)/(7.0)
  public static double sphere(double radius)
  {
    double vs = (4.0/3.0)*pi*radius*radius*radius;
    return vs;
  }
  public static double cylinder(double radius, double height)
  {
    double  vc = pi*radius*radius*height;
    return vc;
  }
  public static double cube(double side)
  {
    double vc = side*side*side;
    return vc;
  }
  public static double box(double length, double breadth, double height)
  {
    double vb = length*breadth*height;
    return vb;
  }
  public static void main(String args[])
  { 
    Scanner sc = new Scanner(System.in);
    double radius = sc.nextDouble();
    volSphere = sphere(radius);
    System.out.println(volSphere);
    double height = sc.nextDouble();
    volCylinder = cylinder(radius, height);
    System.out.println(volCylinder);
    double side = sc.nextDouble();
    volSide = cube(side);
    System.out.println(volSide);
    double length = sc.nextDouble();
    double breadth = sc.nextDouble();
    double height = sc.nextDouble();
    volBox = box(length, breadth, height);
    System.out.println(volBox);
  }
}

Please find the solution code above, and comment if found any issue, it will be resolved as soon as possible. Thank you.


Related Solutions

Create a Java project called Lab3B and a class named Lab3B. Create a second new class...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class named Book. In the Book class: Add the following private instance variables: title (String) author (String) rating (int) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. Add a second constructor that receives only 2 String parameters, inTitle and inAuthor. This constructor should only assign input parameter values to title and...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class named Employee. In the Employee class: Add the following private instance variables: name (String) job (String) salary (double) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. (Refer to the Tutorial3 program constructor if needed to remember how to do this.) Add a public String method named getName (no parameter) that...
Create a Java project called 5 and a class named 5 Create a second new class...
Create a Java project called 5 and a class named 5 Create a second new class named CoinFlipper Add 2 int instance variables named headsCount and tailsCount Add a constructor with no parameters that sets both instance variables to 0; Add a public int method named flipCoin (no parameters). It should generate a random number between 0 & 1 and return that number. (Important note: put the Random randomNumbers = new Random(); statement before all the methods, just under the...
1. Create a new Java project called L2 and a class named L2 2. Create a...
1. Create a new Java project called L2 and a class named L2 2. Create a second class called ArrayExaminer. 3. In the ArrayExaminer class declare the following instance variables: a. String named textFileName b. Array of 20 integers named numArray (Only do the 1st half of the declaration here: int [] numArray; ) c. Integer variable named largest d. Integer value named largestIndex 4. Add the following methods to this class: a. A constructor with one String parameter that...
Step 1: Create a new Java project called Lab5.5. Step 2: Now create a new class...
Step 1: Create a new Java project called Lab5.5. Step 2: Now create a new class called aDLLNode. class aDLLNode { aDLLNode prev;    char data;    aDLLNode next; aDLLNode(char mydata) { // Constructor data = mydata; next = null;    prev = null;    } }; Step 3: In the main() function of the driver class (Lab5.5), instantiate an object of type aDLLNode and print the content of its class public static void main(String[] args) { System.out.println("-----------------------------------------");    System.out.println("--------Create...
Start NetBeans. Create a new project called Lab7. Create a Java main class file using the...
Start NetBeans. Create a new project called Lab7. Create a Java main class file using the class name YourlastnameLab7 with your actual last name. Create a Java class file for a Polygon class. Implement the Polygon class. Add a private instance variable representing the number of sides in the polygon. Add a constructor that takes a single argument and uses it to initialize the number of sides. If the value of the argument is less than three, display an error...
In java: -Create a class named Animal
In java: -Create a class named Animal
Inside “Lab1” folder, create a project named “Lab1Ex3”. Use this project to develop a C++ program...
Inside “Lab1” folder, create a project named “Lab1Ex3”. Use this project to develop a C++ program that performs the following:  Define a function called “Find_Min” that takes an array, and array size and return the minimum value on the array.  Define a function called “Find_Max” that takes an array, and array size and return the maximum value on the array.  Define a function called “Count_Mark” that takes an array, array size, and an integer value (mark) and...
Inside “Lab1”folder, create a project named “Lab1Ex1”. Use this project to write and run a C++...
Inside “Lab1”folder, create a project named “Lab1Ex1”. Use this project to write and run a C++ program that produces:  Define a constant value called MAX_SIZE with value of 10.  Define an array of integers called Class_Marks with MAX_SIZE which contains students Mark. Define a function called “Fill_Array” that takes an array, and array size as parameters. The function fills the odd index of the array randomly in the range of [50- 100] and fills the even index of...
Problem 1 Create a new project called Lab7 Create a class in that project called ListORama...
Problem 1 Create a new project called Lab7 Create a class in that project called ListORama Write a static method in that class called makeLists that takes no parameters and returns no value In makeLists, create an ArrayList object called avengers that can hold String objects. Problem 2 Add the following names to the avengers list, one at a time: Chris, Robert, Scarlett, Clark, Jeremy, Gwyneth, Mark Print the avengers object. You will notice that the contents are displayed in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT