I'm trying to display an error message if the user supplies no command line arguments. I'm getting an error when I type "java sheet12t1" into cmd. I have the rest of my program nailed down, it's just that this part won't work.
The question I'm working with is below, along with my code.
This is the question I'm working with: https://i.stack.imgur.com/YNMJF.png
public class sheet12t1
{
public static void main(String[] args)
{
int projectCategory = Integer.parseInt(args[0]);
int keyServiceType = Integer.parseInt(args[1]);
if (args.length != 2)
System.out.println("Please enter: java sheet12t1 projectCategory serviceType");
else if (args.length == 0)
System.out.println("Please enter two valid inputs.");
else if (projectCategory < 1 || projectCategory > 3)
System.out.println("Please enter valid inputs.");
else if (keyServiceType < 1 || keyServiceType > 3)
System.out.println("Please enter valid inputs.");
else
{
double result = calculateProjectCost(projectCategory, keyServiceType);
System.out.println("Total project cost: " + result);
}
}
public static double calculateProjectCost(int projectCategory, int keyServiceType)
{
double totalCost = 10000;
if (projectCategory == 1)
{
if (keyServiceType == 1) totalCost += 5600.5;
else if (keyServiceType == 2) totalCost += 5500;
else totalCost += 6000;
}
else if (projectCategory == 2)
{
if (keyServiceType == 1) totalCost += 10600.5;
else if(keyServiceType ==2) totalCost += 11000;
else totalCost += 13500;
}
else
{
if (keyServiceType == 1) totalCost += 17000;
else if(keyServiceType == 2) totalCost += 22000;
else totalCost += 25000;
}
return totalCost;
}
}