I'm learning using an Array and Command line argument for Java. We write a program that convert from Celsius degree to Fahrenheit degree. I started a basic idea for my project but not sure I did it right (I'm beginner).
public class Implementation
{
public static void main(String[] args)
{
{
String[] days = new String[7];
days[0] = "Very Cold";
days[1] = "Cold";
days[2] = "Mild";
days[3] = "Very Mild";
days[4] = "Warm";
days[5] = "Very Warm";
days[6] = "Hot";
}
if (args.length != 5)
{
System.out.println("Error! Please try again.");
System.exit(0);
}
else
{
String name;
String convert;
double degree;
String celsius;
String fahrenheit;
name = args[0];
convert = args[1];
degree = Double.parseDouble(args[2]);
celsius = args[3];
fahrenheit = args[4];
System.out.printf("%n%s Celsius is %.2f Fahrenheit\n", args[2], ( 9.0 / 5.0 * (degree + 32)));
}
}
}
When I supply my command line argument, it should be in this form:
Java TempConversion 100 c f
My questions are: Did I do my command line arguments right? It seem like I did something wrong even though I still have the same output. How do I show up my array in the output with specific degree? Follow this:
Below 0 degrees = Very cold
From 0 to 32 = Cold
From 33 to 50 = Mild
From 51 to 60 = Very mild
From 61 to 70 = Warm
From 71 to 90 = Very warm
Above 90 = Hot