Question

In: Computer Science

Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a...

Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a package named threeDimensional and put all 3 of the classes discussed below in this package

Include a header comment to EACH OF your files, as indicated in your instructions. Here's a link describing the header. Note that headers are not meant to be in Javadoc format.

Note that Javadoc is a huge part of your grade for this assignment. Javadoc requires that every class, every field, every constructor, and every method have a general (useful) comment and all relevant tags. This includes @param tags for methods and constructors and @param and @return tags for methods.

  1. Create a Cube class with the following:
    1. 1 data member: an integer named lengthOfSide
    2. 2 constructors: a no-argument constructor that set lengthOfSide to 1 and one that takes lengthOfSide as an argument
    3. A getter and a setter for lengthOfSide
    4. A toString() method for Cube that simply returns the string "Cube: [lengthOfSide]"
    5. A getSurfaceArea() method that returns the surface area of this cube.
    6. A getVolume() method that returns the volume of this cube.
    7. Make sure to Javadoc EVERYTHING!
  2. Create a Sphere class that has everything that the cube class has except:
    1. Instead of lengthOfSide, Sphere has radius.
    2. Note that if you choose to copy and paste, nearly everything will change because of radius
    3. Make sure to Javadoc EVERYTHING! This means that if you copy and paste from Cube, there should be no mention of Cube or lengthOfSide in the javadoc.
  3. Create a third class named Program4 which has a main method. It should make use of Cube and Sphere to do the following:
    1. Create a Scanner named scanner off of standard input.
    2. Create a Cube named firstCube and use the default (no-argument) constructor to populate the reference
    3. Print out firstCube
    4. Prompt the user with "Please enter the length of the side for firstCube: "
    5. Read in the next integer and use it to set the length of the side of firstCube. DO NOT USE A CONSTRUCTOR.
    6. Make new Cubes named secondCube and thirdCube with sides equal to 8 and 3 respectively
    7. Make a new integer named accessorValue and have it store the getter value for firstCube.
    8. Output "First Cube side length: ", "Second Cube surface area: ", and "Third Cube volume: " along with their values (use accessorValue for First Cube)
    9. Output all three Cubes in order along with the labels "First Cube: ", "Second Cube: ", and "Third Cube: " in the appropriate places. Then print out a new line
    10. Repeat steps 1-9 above for Spheres. All variable names, all prompts, and all outputs should make sense.
    11. Remember to Javadoc Program4 and the main method!

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================

// Cube.java

package threeDimensional;

public class Cube {
   private int lengthOfSide;

   public Cube() {
       this.lengthOfSide = 1;
   }

   /**
   * @param lengthOfSide
   */
   public Cube(int lengthOfSide) {
       this.lengthOfSide = lengthOfSide;
   }

   /**
   * @return the lengthOfSide
   */
   public int getLengthOfSide() {
       return lengthOfSide;
   }

   /**
   * @param lengthOfSide
   * the lengthOfSide to set
   */
   public void setLengthOfSide(int lengthOfSide) {
       this.lengthOfSide = lengthOfSide;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Cube [" + lengthOfSide + "]";
   }

   public int getSurfaceArea()
   {
       return 6*lengthOfSide;
   }
   public double getVolume()
   {
       return Math.pow(lengthOfSide,3);
   }
}

==========================================

// Sphere.java

package threeDimensional;

public class Sphere {
   private double radius;

   public Sphere() {
       this.radius = 1.0;
   }

   /**
   * @param radius
   */
   public Sphere(double radius) {
       this.radius = radius;
   }

   /**
   * @return the radius
   */
   public double getRadius() {
       return radius;
   }

   /**
   * @param radius
   * the radius to set
   */
   public void setRadius(double radius) {
       this.radius = radius;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Sphere [" + radius + "]";
   }

   public double getSurfaceArea() {
       return 4 * Math.PI * Math.pow(radius, 2);
   }

   public double getVolume() {
       return (4.0 / 3.0) * Math.PI * Math.pow(radius, 3);
   }
}


===========================================

// Program4.java

package threeDimensional;

import java.util.Scanner;

public class Program4 {

   public static void main(String[] args) {

       /*
       * Creating an Scanner class object which is used to get the inputs
       * entered by the user
       */
       Scanner sc = new Scanner(System.in);
       Cube firstCube=new Cube();
       System.out.println(firstCube);
      
       System.out.print("Please enter the length of the side for firstCube:");
       int side=sc.nextInt();
       firstCube.setLengthOfSide(side);
       Cube secondCube = new Cube(8);
       Cube thirdCub = new Cube(3);
       int accessorValue = firstCube.getLengthOfSide();
       System.out.println("First Cube: ");
       System.out.println("First Cube side length:"+accessorValue);
       System.out.println("Second Cube: ");
       System.out.println("Second Cube surface area: "+secondCube.getSurfaceArea());
       System.out.println("Third Cube:");
       System.out.println("Third Cube volume:"+thirdCub.getVolume());
      

   }

}

===========================================

Output:

=====================Could you plz rate me well.Thank You


Related Solutions

Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a...
Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a package named threeDimensional and put all 3 of the classes discussed below in this package Include a header comment to EACH OF your files, as indicated in your instructions. Here's a link describing the header. Note that headers are not meant to be in Javadoc format. Note that Javadoc is a huge part of your grade for this assignment. Javadoc requires that every class,...
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...
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...
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...
Create a new Java project called lab1 and a class named Lab1 Create a second class...
Create a new Java project called lab1 and a class named Lab1 Create a second class called VolumeCalculator. Add a static field named PI which = 1415 Add the following static methods: double static method named sphere that receives 1 double parameter (radius) and returns the volume of a sphere. double static method named cylinder that receives 2 double parameters (radius & height) and returns the volume of a cylinder. double static method named cube that receives 1 double parameter...
Create a new Java program named AllAboutMe (For JAVA we use blue J) Write code to...
Create a new Java program named AllAboutMe (For JAVA we use blue J) Write code to have the program print your name, favorite color, and three hobbies to a new text file called “AllAboutMe” using PrintStream. Submit code.
Java program Create a public method named saveData for a class named Signal that will hold...
Java program Create a public method named saveData for a class named Signal that will hold digitized acceleration data. Signal has the following field declarations private     double timeStep;               // time between each data point     int numberOfPoints;          // number of data samples in array     double [] acceleration = new double [1000];          // acceleration data     double [] velocity = new double [1000];        // calculated velocity data     double [] displacement = new double [1000];        // calculated disp...
Create a new Java Project named “Packages” from within Eclipse. Following the example in the Week...
Create a new Java Project named “Packages” from within Eclipse. Following the example in the Week 6 lecture, create six packages: Main, add, subtract, multiply, divide, and modulo. ALL of these packages should be within the “src” folder in the Eclipse package Explorer. ALL of the packages should be on the same “level” in the file hierarchy. In the “Main” package, create the “Lab04.java” file and add the needed boilerplate (“Hello, World!” style) code to create the main method for...
Java Programming Create a class named Problem1, and create a main method, the program does the...
Java Programming Create a class named Problem1, and create a main method, the program does the following: - Prompt the user to enter a String named str. - Prompt the user to enter a character named ch. - The program finds the index of the first occurrence of the character ch in str and print it in the format shown below. - If the character ch is found in more than one index in the String str, the program prints...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT