// Guide to Java
// Copyright 2014, by J.T. Streib and T. Soma
// a program to classify a hurricane
import java.util.*;
class ClassifyHurricane {
public static void main(String[] args) {
// declaration and initialization of variables
int windSpeed;
Scanner scanner;
scanner = new Scanner(System.in);
// input a wind speed
System.out.print("Enter the wind speed (mph): ");
windSpeed = scanner.nextInt();
// determine the category of the hurricane
if(windSpeed > 155)
System.out.println("The hurricane is category 5.");
else
if(windSpeed >= 131)
System.out.println("The hurricane is category 4.");
else
if(windSpeed >= 111)
System.out.println("The hurricane is category 3.");
else
if(windSpeed >= 96)
System.out.println("The hurricane is category 2.");
else
if(windSpeed >= 74)
System.out.println("The hurricane is category 1.");
else
if(windSpeed >= 0)
System.out.println("Not a hurricane.");
else
System.out.println("Invalid wind speed.");
}
}
// definition of Hurricane class
class Hurricane {
// data members
private int windSpeed;
private int category;
// constructor
public Hurricane() {
category = 0;
windSpeed = 0;
}
// mutator methods
public void setWindSpeed(int inWindSpeed) {
windSpeed = inWindSpeed;
}
public void setCategory() {
if(windSpeed > 155)
category = 5;
else
if(windSpeed >= 131)
category = 4;
else
if(windSpeed >= 111)
category = 3;
else
if(windSpeed >= 96)
category = 2;
else
if(windSpeed >= 74)
category = 1;
}
// accesor methods
public int getWindSpeed() {
return windSpeed;
}
public int getCategory() {
return category;
}
}