Lab 05

Date and Time Methods

 

Objective:

 

Write a class that will test dates and times inputted by the user and determine whether or not it is valid. This will focus on the usages of methods to organize code.

 

 

Lab Solution

 

Requirements:

 

 

Example Dialog:

 

Enter a date and time (MM/DD hh:mm) and I will determine if it is valid

06/22 3:00

The date and time is valid!

Would you like to exit? Type "quit" to exit or press [ENTER] to continue

 

Enter a date and time (MM/DD hh:mm) and I will determine if it is valid

9/31 12:00

The date and time is not valid

Would you like to exit? Type "quit" to exit or press [ENTER] to continue

 

Enter a date and time (MM/DD hh:mm) and I will determine if it is valid

12/08 13:00

The date and time is not valid

Would you like to exit? Type "quit" to exit or press [ENTER] to continue

quit

Good bye

 

Solution Tests:

  1. Is your name written as a comment in all source files?
  2. Does the solution compile (no syntax errors)?
  3. When entering “06/22 3:00” does the program print that it is valid?
  4. When entering “9/31 12:00” does the program print that it is invalid?
  5. When entering “12/08 13:00” does the program print that it is invalid?

 

 

Lab Report

  1. Create a section named “Problem” and describe this lab’s problem in your own words. (10pts).
  2. Create a section named “Solution Description” and describe how the code solves the problem in your own words. (10pts).
  3. Create a section named “Problems Encountered” and describe the various syntax, run-time, and logic errors that were encountered while implementing the solution. (10pts).
  4. What is the purpose of a parameter for a method.
  5. If a variable is declared in a method, then can it be used outside of that method?
  6. If a method returns nothing, then what should its return type be?
  7. Given the following code snippet, there appears to be some kind of syntax error with this method. Where is the error and how can it be fixed?

  1. Given the following code snippet, there appears to be some kind of syntax error with this method. Where is the error and how can it be fixed?

  1. Given the following code snippet, there does not appear to be a syntax error, but there is a strange logic error where the method always returns 0. Explain the logic error and how best to fix it.

 

 

  1. Given the following code snippet, are there any kind of errors? If so, name the types, where, and how this code can be fixed. Otherwise, what does this code exactly print to the console?

 

 

Finally:

Upload the source code (.JAVA File Extension) and written lab report (.DOC, .DOCX, or .PDF file extension) to the CSCE Dropbox.