Hi im trying to create a code where i get user to input date. I will then manipulate this date to create a cost of travel for each day. Im struggling to add Exceptions to prevent errors from being entered. Can anyone give me some tips on how to do this? My Code:
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
public class Price
{
public static void main (String [] args)
{
userInput();
}
public static void userInput()
{
Scanner scan = new Scanner(System.in);
int month, day, year;
System.out.println("Please enter a month MM: ");
month = scan.nextInt();
System.out.println("Please enter a day DD: ");
day = scan.nextInt();
System.out.println("Please enter a year YYYY: ");
year = scan.nextInt();
System.out.println("You chose: " + month + " /" + day + " /" + year);
}
}
hasNextInt()in the Scanner javadoc.