Driver Class SnowBallFactory.java Abstract class SnowFlake.java SnowFlake Types
ID: 3764698 • Letter: D
Question
Driver Class
SnowBallFactory.java
Abstract class
SnowFlake.java
SnowFlake Types
TypeName.java (i.e. Sheaths.java)
The weather in Tampa Florida is warm most all year round. This does lead to the interesting scenariowhere some people have never seen snow. To help enlighten those individuals on the wonders of snowwe have designed our very own Snow Factory. We as that you help make this a reality by implementingour designs.
We require an Abstract class called SnowFlake. SnowFlake will require any class extending it to set thefollowing 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 doublemultiplied by a factor of randomly numbers from 8 to10.2. The radius is half the size of the diameter3. The type is the one defined in the table2. the melt method should reduce the size of the diameter by afactor of (the type plus the meltModifier). This can beaccomplished by dividing the diameter by (the type plus themeltModifier)
Now that we have the types of snow flakes defined we need toconsider a Factory that will produce them. Forutunately, a skeletonhas been provided. You will be required to make some changes tomake the program work. We will focus on the recursive function
Type Description1 Simple Prisms2 Solid Columns3 Sheaths4 Scrolls On Plates5 Triangular Forms6 Hexagonal Plates7 Hollow Columns8 Cups9 Columns on Plates10 12-branched Star11 Stellar Plates12 Bullet Rosettes13 Capped Columns14 Split Plates & Stars15 Radiating Plates16 Sectored Plates17 Isolated Bullets18 Multiply Capped Columns19 Skeletal Forms20 Radiating Dendrites21 Simple Star22 Simple Needles23 Capped Bullets24 Twin Columns25 Irregulars26 Stellar Dendrites27 Needle Clusters28 Double Plates29 Arrowhead twins30 Rimed31 Fernlike Stellar Dendrites32 Crossed needles33 Hollow Plates34 Crossed Plates35 Graupel
createSnowBall.1. createSnowBall
1. This method has three parameters1. desiredSize2. currentSize3. ArrayList<SnowFlake> snowBall2. This method will recurisively call the create snowball method untill the desired size isreached.3. If the current size is not greater than the desired size1. we will add a snowflake to the snowball using the createSnowFlake method2. increase the current size to account for the new snowflake.
Explanation / Answer
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("nEnter desired size of snowball to be created:");
double desiredSize = input.nextDouble();
System.out.println("Created snow ball of size : " + desiredSize);
createSnowBall(desiredSize, 0, snowBall);
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);
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){
}
private static SnowFlake createSnowFlake()
{
int type = gen.nextInt(2) +1
switch(type)
{
case(1):return new SimpleStar();
case(2):return new StellarDentrites();
}
return null;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.