In: Computer Science
I have an issue this project
Background
The intensity of a hurricane is classified according to the Saffir-Simpson hurricane wind scale. The scale together with wind classifications of lower intensities is shown below:
Hurricane Wind Scale Classification |
Wind Speed Range (MPH) |
Not in scale |
0 – 38 mph |
Tropical storm |
39 – 73 mph |
Category One Hurricane |
74 – 95 mph |
Category Two Hurricane |
96 – 110 mph |
Category Three Hurricane |
111 – 129 mph |
Category Four Hurricane |
130 – 156 mph |
Category Five Hurricane |
157 mph or more |
Assignment
Write a Java program that asks the user to enter the wind speed. Use a series of nested if statements to determine the intensity of the storm using the above table. Output your result.
Validate your input to check for (invalid) negative wind speeds. For invalid wind speeds – output the classification: Invalid input.
Be sure to include a comment with your name, date, and a short description of the program.
Begin your program as follows:
import java.util.Scanner;
// TODO - add name, date, and purpose of
program here
public class Main {
public static Scanner
input = new
Scanner(System.in);
public static void
main(String[] args) {
long
speed;
String classification;
//
TODO - write your program here
}
}
Example Output
Enter wind speed (mph): 129
Classification: Category Three Hurricane
Additional Information
Do not include unnecessary if statements or unnecessary logical AND/OR clauses in your code.
My code
public class Main { public static Scanner input = new Scanner(System.in); public static void main(String[] args) { long speed; String classification; void classify(long speed){ System.out.print("Categoty is"); if (speed >= 0 && speed <= 38) {// cheking for category 1 System.out.println("Not in scale"); } else if (speed >= 39 && speed <= 73) {// cheking for category 2 System.out.println("Topical storm"); } else if (speed >= 74 && speed <= 95) {// cheking for category 3 System.out.println("Category One Hurricane"); } else if (speed >= 96 && speed <= 110) {// cheking for category 4 System.out.println("Category Two Hurricane"); } else if (speed >= 111 && speed <= 129) {// cheking for category 5 System.out.println("Category Three Hurricane"); } else if (speed >= 130 && speed <= 156) {// cheking for category 6 System.out.println("Category Four Hurricane"); } else if (speed >= 157 && speed <= more) {// cheking for category 7 System.out.println("Category Five Hurricane"); } } } }
import java.util.Scanner;
public class Main
{
public static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
long speed;
String classification="";
System.out.println("Enter wind speed (mph): ");
speed= Main.input.nextLong();
if (speed >= 0 && speed <= 38) {// cheking for
category 1
classification="Not in scale";
}
else if (speed >= 39 && speed <= 73) {// cheking for
category 2
classification="Topical storm";
}
else if (speed >= 74 && speed <= 95) {// cheking for
category 3
classification="Category One Hurricane";
}
else if (speed >= 96 && speed <= 110) {// cheking for
category 4
classification="Category Two Hurricane";
}
else if (speed >= 111 && speed <= 129) {// cheking
for category 5
classification="Category Three Hurricane";
}
else if (speed >= 130 && speed <= 156) {// cheking
for category 6
classification="Category Four Hurricane";
}
else if (speed >= 157) {// cheking for category 7
classification="Category Five Hurricane";
}
if(speed>=0)
{
System.out.print("Category is "+classification);
}
else
{
System.out.println("Invalid input.");
}
}
}
OUTPUT:
Enter wind speed (mph):
160
Category is Category Five Hurricane