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

*JAVA CODE* write a code with a public class called Hurricane -provide a private

ID: 3595932 • Letter: #

Question

*JAVA CODE*

write a code with a public class called Hurricane

-provide a private instance variable of type int named category and initialize it to 1.

-provide a private instance variable of type string named name and initialize it to " "

-provide a public static variable of type int named numHurricans and initialize it to 0

-provide one public constructor which takes no parameters, but has a statement in it which outputs the following: i am a hurrican.

-privide public get and set methods for category and for name

-provide a public method named changeCategory, which takes an integer value as a parameter and alters the categroy of the hurricane (up or down)

-create a main method which does the following:

-instantiates 2 objects of Hurrican,a nd sets their category to any value btwn 1 and 5 inclusive and give each hurrican its own name

-my name is: and outputs hurrican name

-my category is: and outputs with it the value of category you chose

-also, within your main method change the categroy of each hurrican up or down and output th the screen lines for each hurrican which say:

my name is:

my catgeory is:

finally, in your main method output a line that shows the number or hurricane instances in your program.

Explanation / Answer

public class Hurricane

{

private int category = 1 ;

private String name = "" ;

public static int numHurricanes = 0 ;

public Hurricane()

{

numHurricanes = numHurricanes + 1;

System.out.println("I am a hurrican");

}

public void setName( String n )

{

name = n;

}

public void setCategory( int n )

{

category = n;

}

public int getCategory()

{

return category;

}

public String getName()

{

return name;

}

public void changeCategoryUp( int n )

{

category = category + n;

}

public void changeCategoryDown( int n )

{

category = category - n;

}

public static void main( String args[] )

{

/* creating object references */

Hurricane h1 = new Hurricane();

Hurricane h2 = new Hurricane();

/* setting the parametres */

h1.setCategory(2);

h1.setName( "First Hurricane" );

h2.setCategory(3);

h2.setName( " Second Hurricane" );

/* printing the parametres */

System.out.println("my name is :" + h1.getName());

System.out.println("my category is :" + h1.getCategory());

System.out.println("my name is :" + h2.getName());

System.out.println("my category is :" + h2.getCategory());

/* changing the category */

h1.changeCategoryUp(2);

h2.changeCategoryUp(1);

  

/* printing the changes */

System.out.println("my name is :" + h1.getName());

System.out.println("my category is :" + h1.getCategory());

System.out.println("my name is :" + h2.getName());

System.out.println("my category is :" + h2.getCategory());

/* printing the num of hurricanes */

System.out.println("Num of Hurricanes :" + Hurricane.numHurricanes);

}

}

/* hope this helps */

/* if any queries please comment */

/* thank you */