Java Program Requirements: Create a DodecahedronList class that stores the name of the list and an ArrayList of Dodecahedron objects. It also includes methods that return the name of the list, number of Dodecahedron objects in the DodecahedronList, total surface area, total volume, average surface area, average volume, and average surface to volume ratio for all Dodecahedron objects in the DodecahedronList. The toString method returns a String containing the name of the list followed by each Dodecahedron in the ArrayList, and a summaryInfo method returns summary information about the list. Design: The DodecahedronList class has two fields, a constructor, and methods as outlined below. (1) Fields (instance variables): a String representing the name of the list and an ArrayList of Dodecahedron objects. These are the only fields (instance variables) that this class should have. (2) Constructor: Your DodecahedronList class must contain a constructor that accepts a parameter of type String representing the name of the list and a parameter of type ArrayList<Dodecahedron> representing the list of Dodecahedron objects. These parameters should be used to assign the fields described above (instance variables). (3) Methods: The methods for DodecahedronList are described below. o getName: Returns a String representing the name of the list. o numberOfDodecahedrons: Returns an int representing the number of Dodecahedron objects in the DodecahedronList.  o totalSurfaceArea: Returns a double representing the total surface areas for all Dodecahedron objects in the list.  o totalVolume: Returns a double representing the total volumes for all Dodecahedron objects in the list.  o averageSurfaceArea: Returns a double representing the average surface area for all Dodecahedron objects in the list. o averageVolume: Returns a double representing the average volume for all Dodecahedron objects in the list.  o averageSurfaceToVolumeRatio: Returns a double representing the average surface to volume ratio for all Dodecahedron objects in the list.  o toString: Returns a String (does not begin with \n) containing the name of the list followed by each Dodecahedron in the ArrayList. In the process of creating the return result, this toString() method should include a while loop that calls the toString() method for each Dodecahedron object in the list (adding a \n before and after each). Be sure to include appropriate newline escape sequences.  o summaryInfo: Returns a String (does not begin with \n) containing the name of the list (which can change depending of the value read from the file) followed by various summary items: number of Dodecahedrons, total surface area, total volume, average surface area, average volume, and average surface to volume ratio. Use "#,##0.0##" as the pattern to format the double values.  This is the code I have written for the first part of the program called Dodecahedron.java, I am requesting help with the second part that is described above. import java.text.DecimalFormat; public class Dodecahedron {   private String label = "";   private String color = "";   private double edge = 0;      public Dodecahedron(String labelIn, String colorIn, double edgeIn)    {      setLabel(labelIn);      setColor(colorIn);      setEdge(edgeIn);   }   public String getLabel()   {      return  label;   }      public boolean setLabel(String labelIn)   {      boolean isSetLabel = false;      if (labelIn != null)      {                   label = labelIn.trim();                  isSetLabel =  true;      }      return isSetLabel;   }   public String getColor()   {      return color;   }   public boolean setColor(String colorIn)   {      boolean isSetColor = false;      if (colorIn != null)       {                  color = colorIn.trim();                  isSetColor = true;      }      return isSetColor;   }      public double getEdge()    {      return edge;   }   public boolean setEdge(double edgeIn)   {      boolean isSetEdge = false;      if (edgeIn > 0)      {         edge = edgeIn;         isSetEdge = true;      }      return isSetEdge;   }      public double surfaceArea()   {      double a = (3 * Math.sqrt(25 + 10 * Math.sqrt(5)) * Math.pow(edge, 2));      return a;   }      public double volume()   {      double v = (15 + 7 * Math.sqrt(5)) / 4 * Math.pow(edge, 3);         return v;   }      public double surfaceToVolumeRatio()   {      double s = surfaceArea() / volume();      return s;   }      public String toString()   {      DecimalFormat fmt = new DecimalFormat("#,##0.0##");      String output = "Dodecahedron \"" + label + "\" is \"" + color          + "\" with 30 edges of length " + edge + " units.\n";      output += "\tsurface area = " + fmt.format(surfaceArea())         + " square units \n";      output += "\tvolume = " + fmt.format(volume()) + " cubic units\n";      output += "\tsurface/volume ratio = "          + fmt.format(surfaceToVolumeRatio());      return output;   }}

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 9PE
icon
Related questions
Question

Java Program

Requirements: Create a DodecahedronList class that stores the name of the list and an ArrayList of Dodecahedron objects. It also includes methods that return the name of the list, number of Dodecahedron objects in the DodecahedronList, total surface area, total volume, average surface area, average volume, and average surface to volume ratio for all Dodecahedron objects in the DodecahedronList. The toString method returns a String containing the name of the list followed by each Dodecahedron in the ArrayList, and a summaryInfo method returns summary information about the list.

Design: The DodecahedronList class has two fields, a constructor, and methods as outlined below.

(1) Fields (instance variables): a String representing the name of the list and an ArrayList of Dodecahedron objects. These are the only fields (instance variables) that this class should have.

(2) Constructor: Your DodecahedronList class must contain a constructor that accepts a parameter of type String representing the name of the list and a parameter of type ArrayList<Dodecahedron> representing the list of Dodecahedron objects. These parameters should be used to assign the fields described above (instance variables).

(3) Methods: The methods for DodecahedronList are described below.

o getName: Returns a String representing the name of the list.

o numberOfDodecahedrons: Returns an int representing the number of Dodecahedron objects in the DodecahedronList. 

o totalSurfaceArea: Returns a double representing the total surface areas for all Dodecahedron objects in the list. 

o totalVolume: Returns a double representing the total volumes for all Dodecahedron objects in the list. 

o averageSurfaceArea: Returns a double representing the average surface area for all Dodecahedron objects in the list.

o averageVolume: Returns a double representing the average volume for all Dodecahedron objects in the list. 

o averageSurfaceToVolumeRatio: Returns a double representing the average surface to volume ratio for all Dodecahedron objects in the list. 

o toString: Returns a String (does not begin with \n) containing the name of the list followed by each Dodecahedron in the ArrayList. In the process of creating the return result, this toString() method should include a while loop that calls the toString() method for each Dodecahedron object in the list (adding a \n before and after each). Be sure to include appropriate newline escape sequences. 

o summaryInfo: Returns a String (does not begin with \n) containing the name of the list (which can change depending of the value read from the file) followed by various summary items: number of Dodecahedrons, total surface area, total volume, average surface area, average volume, and average surface to volume ratio. Use "#,##0.0##" as the pattern to format the double values. 

This is the code I have written for the first part of the program called Dodecahedron.java, I am requesting help with the second part that is described above.

import java.text.DecimalFormat;
 
public class Dodecahedron
{
   private String label = "";
   private String color = "";
   private double edge = 0;
  

   public Dodecahedron(String labelIn, String colorIn, double edgeIn)
   {
      setLabel(labelIn);
      setColor(colorIn);
      setEdge(edgeIn);
   }

   public String getLabel()
   {
      return  label;
   }
  
   public boolean setLabel(String labelIn)
   {
      boolean isSetLabel = false;
      if (labelIn != null)
      {
         
         label = labelIn.trim();
        
         isSetLabel =  true;
      }
      return isSetLabel;
   }

   public String getColor()
   {
      return color;
   }

   public boolean setColor(String colorIn)
   {
      boolean isSetColor = false;
      if (colorIn != null)
      {
        
         color = colorIn.trim();
        
         isSetColor = true;
      }
      return isSetColor;
   }
  
   public double getEdge()
   {
      return edge;
   }

   public boolean setEdge(double edgeIn)
   {
      boolean isSetEdge = false;
      if (edgeIn > 0)
      {
         edge = edgeIn;
         isSetEdge = true;
      }
      return isSetEdge;
   }
  
   public double surfaceArea()
   {
      double a = (3 * Math.sqrt(25 + 10 * Math.sqrt(5)) * Math.pow(edge, 2));
      return a;
   }
  
   public double volume()
   {
      double v = (15 + 7 * Math.sqrt(5)) / 4 * Math.pow(edge, 3);  
      return v;
   }
  
   public double surfaceToVolumeRatio()
   {
      double s = surfaceArea() / volume();
      return s;
   }
  
   public String toString()
   {
      DecimalFormat fmt = new DecimalFormat("#,##0.0##");
      String output = "Dodecahedron \"" + label + "\" is \"" + color
         + "\" with 30 edges of length " + edge + " units.\n";
      output += "\tsurface area = " + fmt.format(surfaceArea())
         + " square units \n";
      output += "\tvolume = " + fmt.format(volume()) + " cubic units\n";
      output += "\tsurface/volume ratio = "
         + fmt.format(surfaceToVolumeRatio());
      return output;
   }
}


Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 4 images

Blurred answer
Knowledge Booster
Passing Array as Argument
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT