fork(10) download
  1. /* Program Name: BadDate.java
  2.   Function: This program determines if a date entered by the user is valid.
  3.   Input: Interactive
  4.   Output: Valid date is printed or user is alerted that an invalid date was entered.
  5. */
  6.  
  7. import javax.swing.JOptionPane;
  8. import java.util.Scanner;
  9. public class BadDate
  10. {
  11. public static void main(String args[])
  12. {
  13. // Declare variables
  14. Scanner userInput = new Scanner (System.in);
  15. String yearString;
  16. String monthString;
  17. String dayString;
  18. int year;
  19. int month;
  20. int day;
  21. boolean validDate = true;
  22. final int MIN_YEAR = 0, MIN_MONTH = 1, MAX_MONTH = 12, MIN_DAY = 1, MAX_DAY = 31;
  23.  
  24. // This is the work of the housekeeping() method
  25. // Get the year, then the month, then the day
  26.  
  27. System.out.println("Please enter the Month");
  28. monthString = userInput.nextLine();
  29. System.out.println("Please enter the Day");
  30. dayString = userInput.nextLine();
  31. System.out.println("Please enter the Year");
  32. yearString = userInput.nextLine();
  33.  
  34.  
  35. // Convert Strings to integers
  36.  
  37. month = Integer.parseInt(monthString);
  38. day = Integer.parseInt(dayString);
  39. year = Integer.parseInt(yearString);
  40.  
  41. // This is the work of the detailLoop() method
  42. // Check to be sure date is valid
  43. if( year <= MIN_YEAR ) // invalid year
  44. validDate = false;
  45. else if ( month < MIN_MONTH || month > MAX_MONTH ) // invalid month
  46. validDate = false;
  47. else if ( day < MIN_DAY || day > MAX_DAY ) // invalid day
  48. validDate = false;
  49.  
  50.  
  51.  
  52. // This is the work of the endOfJob() method
  53. // Test to see if date is valid and output date and whether it is valid or not
  54. if( validDate == true )
  55.  
  56. { System.out.println("(month)/(day)/(year) is a valid date");
  57. // Output statement
  58.  
  59. }
  60. else
  61. { System.out.println("(month)/(day)/(year) is an invalid date");
  62. // Output statement
  63.  
  64. }
  65.  
  66. } // end of main() method
  67.  
  68. } // end of BadDate class
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:9: error: class BadDate is public, should be declared in a file named BadDate.java
public class BadDate
       ^
1 error
stdout
Standard output is empty