Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The weather in Tampa Florida is warm most all year round. This does lead to the

ID: 3764099 • Letter: T

Question

The weather in Tampa Florida is warm most all year round. This does lead to the interesting scenario where some people have never seen snow. To help enlighten those individuals on the wonders of snow we have designed our very own Snow Factory. We as that you help make this a reality by implementing our designs

We require an Abstract class called SnowFlake. SnowFlake will require any class extending it to set the following variables:

• type • radius • diameter • meltModifier (0.05) • Random Number Generator (static) • snowFall (static)

The following methods are required: • getType() • getDiameter() • getRadius() • toString() The follwing method is abstract: • melt();

The list to the right contains the  common types of SnowFlakes. Create a class that extends the SnowFlake class for each of them. Source: http://www.snowcrystals.com/guide/snowtypes4.jpg Each snowflake should do the following:

1. Initialize the variables in the super class

1. The diameter should be of a random size of type double multiplied by a factor of randomly numbers from 8 to 10.

2. The radius is half the size of the diameter

3. The type is the one defined in the table

2. the melt method should reduce the size of the diameter by a factor of (the type plus the meltModifier). This can be accomplished by dividing the diameter by (the type plus the meltModifier) Now that we have the types of snow flakes defined we need to consider a Factory that will produce them. Forutunately, a skeleton has been provided. You will be required to make some changes to make the program work. We will focus on the recursive function:

createSnowBall.

1. createSnowBall

1. This method has three parameters 1. desiredSize 2. currentSize 3. ArrayList snowBall

2. This method will recurisively call the create snowball method untill the desired size is reached.

3. If the current size is not greater than the desired size 1. we will add a snowflake to the snowball using the createSnowFlake method 2. increase the current size to account for the new snowflake.

Snowball list:

1 Simple Prisms 2 Solid Columns 3 Sheaths 4 Scrolls On Plates 5 Triangular Forms 6 Hexagonal Plates 7 Hollow Columns 8 Cups 9 Columns on Plates 1012-branched Star 11 Stellar Plates 12 Bullet Rosettes 13 Capped Columns 14 Split Plates & Stars 15 Radiating Plates 16 Sectored Plates 17Isolated Bullets 18 Multiply Capped Columns 19 Skeletal Forms 20 Radiating Dendrites 21 Simple Star 22 Simple Needles 23 Capped Bullets 24 Twin Columns 25Irregulars 26 Stellar Dendrites 27 Needle Clusters 28 Double Plates 29 Arrowhead twins 30 Rimed 31 Fernlike Stellar Dendrites 32 Crossed needles 33 Hollow Plates 34 Crossed Plates 35 Graupe

The value associated with snowball is also melt rate

Skeleton of Driver

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class SnowBallFactory {
   static Random gen = new Random(System.currentTimeMillis());
  
   public static void main(String[] args) {
       ArrayList<SnowFlake> snowBall = new ArrayList<SnowFlake>();
       Scanner input = new Scanner(System.in);
       System.out.println("Snow Ball Factory up and running.");
      
       int balls = 3;
       for(int j = 0; j < balls; j++){
           System.out.print(" Enter desired size of snowball to be created:");
           double desiredSize = input.nextDouble();
          
           System.out.println("Created snow ball of size : " + desiredSize);
           createSnowBall(desiredSize, 0, snowBall);

           // Snow ball analysis
           System.out.println("There are " + snowBall.size() + " snowFlakes.");
           double size = 0.0;
           for (SnowFlake s : snowBall) {
               size += s.getDiameter();
           }
           System.out.println("Actual Size " + size);

           // How long to melt?
           int minutes = 0;
           while (!snowBall.isEmpty()) {
               for (SnowFlake s : snowBall) {
                   s.melt();
               }
               for (int i = snowBall.size() - 1; i >= 0; i--) {
                   if (snowBall.get(i).getDiameter() < 1.0) {
                       snowBall.remove(i);
                   }
               }
               minutes++;
           }
           System.out.println("It took " + minutes + " minutes to melt the snowball.");
       }
       System.out.println("SnowFall : " + SnowFlake.snowFall);
       input.close();
      
   }
  
   public static void createSnowBall(double desiredSize, double currentSize, ArrayList<SnowFlake> snowball){
   //Add code here to recursively call createSnowBall.  
   }

   private static SnowFlake createSnowFlake() {
       //Add code to match the types which you have chosen to implement.
       int type = gen.nextInt(2) +1;
       switch(type){
       case(1):return new SimpleStar();
       case(2):return new StellarDentrites();
       }
       return null;
      
   }

}

Explanation / Answer

SnowFlake class:

import java.util.*;
public abstract class SnowFlake
{
   protected int type;
   private double radius;
   protected double diameter;
   protected double meltModifier;
  
   public static Random RandomNumGen = new Random();
   public static double snowFall;
  
   public SnowFlake()
   {
       //nothing to do!
   }
   public SnowFlake(int type)
   {
       this.type = type;
      
       this.diameter = RandomNumGen.nextDouble()*RandomNumGen.nextInt(2) + 8;
       //System.out.println("Diameter: "+this.diameter);
       this.radius = this.diameter/2;      
       this.meltModifier = 0.05;
   }
  
   public int getType() {
       return type;
   }
   public double getRadius() {
       return radius;
   }
   public double getDiameter() {
       return diameter;
   }
  
   public String toString()
   {
       return "";
   }
   public abstract void melt();
  
  
}

//#############################################################################

SnowFlakeTypes class:


public class SnowFlakeTypes
{
   static class SimplePrisms extends SnowFlake
   {

       public SimplePrisms()
       {
           super(1);
       }
      

       @Override
       public void melt() {
           double meltSize = (this.diameter/(this.type+this.meltModifier));
           System.out.println("Melting: "+this.diameter+" "+(this.type+this.meltModifier)+" "+meltSize);
           this.diameter -= meltSize;
          
       }

   }
  
   static class SolidColumns extends SnowFlake
   {

       public SolidColumns()
       {
           super(2);
       }
      

       @Override
       public void melt() {
           double meltSize = (this.diameter/(this.type+this.meltModifier));
           System.out.println("Melting: "+this.diameter+" "+(this.type+this.meltModifier)+" "+meltSize);
           this.diameter -= meltSize;
          
       }

   }
  
  
   static class Sheaths extends SnowFlake
   {

       public Sheaths()
       {
           super(3);
       }
      

       @Override
       public void melt() {
           double meltSize = (this.diameter/(this.type+this.meltModifier));
           System.out.println("Melting: "+this.diameter+" "+(this.type+this.meltModifier)+" "+meltSize);
           this.diameter -= meltSize;
          
       }

   }

   static class ScrollsOnPlates extends SnowFlake
   {

       public ScrollsOnPlates()
       {
           super(4);
       }
      

       @Override
       public void melt() {
           double meltSize = (this.diameter/(this.type+this.meltModifier));
           System.out.println("Melting: "+this.diameter+" "+(this.type+this.meltModifier)+" "+meltSize);
           this.diameter -= meltSize;
          
       }

   }
  
   static class TriangularForms extends SnowFlake
   {

       public TriangularForms()
       {
           super(5);
       }
      

       @Override
       public void melt() {
           double meltSize = (this.diameter/(this.type+this.meltModifier));
           System.out.println("Melting: "+this.diameter+" "+(this.type+this.meltModifier)+" "+meltSize);
           this.diameter -= meltSize;
          
       }

   }
  
   static class HexagonalPlates extends SnowFlake
   {

       public HexagonalPlates()
       {
           super(6);
       }
      

       @Override
       public void melt() {
           double meltSize = (this.diameter/(this.type+this.meltModifier));
           System.out.println("Melting: "+this.diameter+" "+(this.type+this.meltModifier)+" "+meltSize);
           this.diameter -= meltSize;
          
       }

   }
  
   static class HollowColumns extends SnowFlake
   {

       public HollowColumns()
       {
           super(7);
       }
      

       @Override
       public void melt() {
           double meltSize = (this.diameter/(this.type+this.meltModifier));
           System.out.println("Melting: "+this.diameter+" "+(this.type+this.meltModifier)+" "+meltSize);
           this.diameter -= meltSize;
          
       }

   }

   static class Cups extends SnowFlake
   {

       public Cups()
       {
           super(8);
       }
      

       @Override
       public void melt() {
           double meltSize = (this.diameter/(this.type+this.meltModifier));
           System.out.println("Melting: "+this.diameter+" "+(this.type+this.meltModifier)+" "+meltSize);
           this.diameter -= meltSize;
          
       }

   }
   static class ColumnsonPlates extends SnowFlake
   {

       public ColumnsonPlates()
       {
           super(9);
       }
      

       @Override
       public void melt() {
           double meltSize = (this.diameter/(this.type+this.meltModifier));
           System.out.println("Melting: "+this.diameter+" "+(this.type+this.meltModifier)+" "+meltSize);
           this.diameter -= meltSize;
          
       }

   }

   static class TwelvebranchedStar extends SnowFlake
   {

       public TwelvebranchedStar()
       {
           super(10);
       }
      

       @Override
       public void melt() {
           double meltSize = (this.diameter/(this.type+this.meltModifier));
           System.out.println("Melting: "+this.diameter+" "+(this.type+this.meltModifier)+" "+meltSize);
           this.diameter -= meltSize;
          
       }
   }

}

//##############################################################################

SnowBallFactory class:

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class SnowBallFactory {
   static Random gen = new Random(System.currentTimeMillis());

   public static void main(String[] args) {
       ArrayList<SnowFlake> snowBall = new ArrayList<SnowFlake>();
       Scanner input = new Scanner(System.in);
       System.out.println("Snow Ball Factory up and running.");

       int balls = 3;
       for (int j = 0; j < balls; j++) {
           System.out.print(" Enter desired size of snowball to be created:");
           double desiredSize = input.nextDouble();

           System.out.println("Created snow ball of size : " + desiredSize);
           createSnowBall(desiredSize, 0, snowBall);
           // Snow ball analysis
           System.out.println("There are " + snowBall.size() + " snowFlakes.");
           double size = 0.0;
           for (SnowFlake s : snowBall) {
               size += s.getDiameter();
           }
           System.out.println("Actual Size " + size);
           // How long to melt?
           int minutes = 0;
           while (!snowBall.isEmpty()) {
               for (SnowFlake s : snowBall) {
                   s.melt();
               }
               for (int i = snowBall.size() - 1; i >= 0; i--) {
                   if (snowBall.get(i).getDiameter() < 1.0) {
                       snowBall.remove(i);
                   }
               }
               minutes++;
           }
           System.out.println("It took " + minutes + " minutes to melt the snowball.");
       }
       System.out.println("SnowFall : " + SnowFlake.snowFall);
       input.close();

   }

   public static void createSnowBall(double desiredSize, double currentSize, ArrayList<SnowFlake> snowball) {
       // Add code here to recursively call createSnowBall.
       if(currentSize <= desiredSize)
       {
           SnowFlake s = createSnowFlake();
           snowball.add(s);
           currentSize += s.getDiameter();
           //System.out.println("Current Size: "+currentSize+" Desiref Size: "+desiredSize+" SnowFalke Size: "+s.getDiameter());
           createSnowBall(desiredSize, currentSize, snowball);
       }
   }

   private static SnowFlake createSnowFlake() {
       // Add code to match the types which you have chosen to implement.
       int type = gen.nextInt(10) + 1;
       switch (type) {
       case (1):
           return new SnowFlakeTypes.SimplePrisms();
       case (2):
           return new SnowFlakeTypes.SolidColumns();
       case (3):
           return new SnowFlakeTypes.Sheaths();
       case (4):
           return new SnowFlakeTypes.ScrollsOnPlates();
       case (5):
           return new SnowFlakeTypes.TriangularForms();
       case (6):
           return new SnowFlakeTypes.HexagonalPlates();
       case (7):
           return new SnowFlakeTypes.HollowColumns();
       case (8):
           return new SnowFlakeTypes.Cups();
       case (9):
           return new SnowFlakeTypes.ColumnsonPlates();
       case (10):
           return new SnowFlakeTypes.TwelvebranchedStar();
       }
       return null;

   }
}