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

/*Solution Description:

Created App as per the instruction and added the ss for the same to give you an idea

In that  3 classes as mentioned with a basic explanation.

Please give thumbs up for the solution.

*/

1. Project :

2.Cube and Sphere Class :


public class Cube {
   int loengthOfSide;

  
  
   //Constructor with no arguments
   public Cube() {
       this.loengthOfSide = 1;
   }
  
   /*Constructor with an argument
   * @Param int type lengthOfSide of the cube*/
   public Cube(int loengthOfSide) {
       this.loengthOfSide = loengthOfSide;
   }

   /*Gtetters and Setters
   * */
   /*@return type int gives length of sides of cube*/
   public int getLoengthOfSide() {
       return loengthOfSide;
   }

   /*@Param of type int sets length of sides of the cube*/
   public void setLoengthOfSide(int loengthOfSide) {
       this.loengthOfSide = loengthOfSide;
   }

   /*toString method
   * @return String contains info of Cube class*/
   @Override
   public String toString() {
       return "Cube [" + loengthOfSide + "]";
   }
  
   /*
   * @return of type int surface area of the cube*/
   public int getSurfaceArea() {
       return 6*this.loengthOfSide*this.loengthOfSide;
   }
  
   /*
   * @return of type int volume of the of the cube*/
   public int getVolume() {
       return this.loengthOfSide*this.loengthOfSide*this.loengthOfSide;
   }
}

################################################################


public class Sphere {
   private int radius;
  
   //Constructor with no arguments
   public Sphere() {
       this.radius = 1;
   }
  
   /*Constructor with an argument
   * @Param int type radius of the Sphere*/
   public Sphere(int radius) {
       this.radius = radius;
   }

   /*Gtetters and Setters
   * */
   /*@return type int gives radius of Sphere*/
   public int getRadius() {
       return radius;
   }
  
   /*@param type int radius of Sphere*/
   public void setRadius(int radius) {
       this.radius = radius;
   }

   /*toString method
   * @return String contains info of Sphere class*/
   @Override
   public String toString() {
       return "Sphere [" + radius + "]";
   }
  
  

   /*
   * @return of type double surface area of the Sphere*/
   public double getSurfaceArea() {
       //Math.pi is java inbuilt variable to define pi
       return 4*Math.PI*this.radius*this.radius;
   }
  
   /*
   * @return of type double volume of the of the Sphere*/
   public double getVolume() {
       return (4/3)*Math.PI*this.radius*this.radius*this.radius;
   }
}

3.Program4 class:

import java.util.Scanner;

public class Program4 {

   public static void main(String[] args) {
       // Scanner
       Scanner scanner = new Scanner(System.in);
      
       //Cubes
       Cube firstCube = new Cube();
       System.out.println(firstCube.toString());
      
       System.out.println("Please enter the length of the side for firstCube: ");
       int length = scanner.nextInt();
      
       firstCube.setLoengthOfSide(length);
      
       Cube secondCube = new Cube(8);
       Cube thirdCube = new Cube(3);
       int accessorValue = firstCube.getLoengthOfSide();
      
       System.out.println("First Cube: "+accessorValue+ "\nSecond Cube: "+secondCube.getSurfaceArea()+", and \nThird Cube: "+thirdCube.getVolume());
      
       //Spheres
       Sphere firstSphere = new Sphere();
       System.out.println(firstSphere.toString());
      
       System.out.println("Please enter the radius of the firstSphere: ");
       int rad = scanner.nextInt();
      
       firstSphere.setRadius(rad);
      
       Sphere secondSphere = new Sphere(8);
       Sphere thirdSphere = new Sphere(3);
       int accessorValueSphere = firstSphere.getRadius();
      
       System.out.println("First Sphere: "+accessorValueSphere+ "\nSecond Sphere: "+secondSphere.getSurfaceArea()+", and \nThird Sphere: "+thirdSphere.getVolume());
      
   }

}


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