PRG420 Week 5 Individual Assignment Coding a Program Containing Exception Handling

Availability: In stock

Regular Price: $10.00

Special Price: $7.00

OR

PRG420 Week 5 Individual Assignment Coding a Program Containing Exception Handling Output and coding

Double click on above image to view full picture

Zoom Out
Zoom In

More Views

Quick Overview

PRG420 Week 5 Individual Assignment Coding a Program Containing Exception Handling


Individual: Coding a Program Containing Exception Handling


Includes Working Java Build and Program File and Explanation of Code
Resource:  Week Five Coding Assignment Zip File (starter code for this assignment that includes placeholders)
For this assignment, you will apply what you learned in analyzing a simple Java™ program by writing your own Java™ program. The Java™ program you write should do the following:
• Organize the code capable of throwing an exception of type ParseException as a try block.
• Include a catch block to handle a ParseException error thrown by the try block.
• Include a hard-coded error that results in a ParseException to prove that the code can catch and handle this type of exception.
Complete this assignment by doing the following:
1. Download and unzip the linked Week Five Coding Assignment Zip File.
2. Add comments to the code by typing your name and the date in the multi-line comment header.
3. Replace the following lines with Java™ code as directed in the file:
• LINE 1
• LINE 2
4. Replace the value assigned with one of the variables so that the program throws an exception.
5. Comment each line of code you add to explain what you intend the code to do. Be sure to include a comment for the replacement value you added in Step 4 that causes the program to throw an exception.
6. Test and modify your Java™ program until it runs without errors and produces the results described above.
Note: Refer to this week's analyzing code assignment if you need help.
Submit your Java application file using the Assignment Files tab.


/********************************************************************
* Program:    PRG420Week5_CodingAssignment
* Purpose:       Week 5 Individual Assignment #2
* Programmer:    Iam A. Student
* Class:         PRG/420  PRG420 PRG 420
* Creation Date:   TODAY'S DATE GOES HERE
*********************************************************************
*
*********************************************************************
* Program Summary:
* This program converts a given date to a string.  
* The code includes exception handling for a ParseException.
************************************************************************************/
package prg420week5_codingassignment;
import java.util.*;
import java.text.*;
public class PRG420Week5_CodingAssignment {
 public static void main(String[] args){
  // The getInstance() method returns a Calendar object whose calendar fields have been initialized with the current date and time.
  Calendar calendar = Calendar.getInstance(); {
  LINE 1. BEGIN THE TRY BLOCK.
  String str_date="01-Nov-17"; // Declare a string that we will use later to format a date like this: ##-XXX-##
  DateFormat formatter; // Declare an object of type DateFormat so that we can call its parse() method later
  Date myFormattedDate; // Declare a variable of type Date to hold the formatted date
  formatter = new SimpleDateFormat("dd-MMM-yy"); // Assign a specific date format to the formatter variable
  // The given date is taken as a string that is converted into a date type by using
  // the parse() method
  myFormattedDate = (Date)formatter.parse(str_date); // setting up the format
  System.out.println("The formatted date is " + myFormattedDate);
  System.out.println("Today is " +calendar.getTime() );
  LINE 2. WRITE THE CATCH BLOCK TO CATCH EXCEPTIONS OF TYPE ParseException (TO HANDLE EXCEPTION, SIMPLY PRINT THE EXCEPTION)
  }
 }
}

* Required Fields

Regular Price: $10.00

Special Price: $7.00

Details

PRG420 Week 5 Individual Assignment Coding a Program Containing Exception Handling

Individual: Coding a Program Containing Exception Handling

Includes Working Java Build and Program File and Explanation of Code
Resource:  Week Five Coding Assignment Zip File (starter code for this assignment that includes placeholders)
For this assignment, you will apply what you learned in analyzing a simple Java™ program by writing your own Java™ program. The Java™ program you write should do the following:
• Organize the code capable of throwing an exception of type ParseException as a try block.
• Include a catch block to handle a ParseException error thrown by the try block.
• Include a hard-coded error that results in a ParseException to prove that the code can catch and handle this type of exception.
Complete this assignment by doing the following:
1. Download and unzip the linked Week Five Coding Assignment Zip File.
2. Add comments to the code by typing your name and the date in the multi-line comment header.
3. Replace the following lines with Java™ code as directed in the file:
• LINE 1
• LINE 2
4. Replace the value assigned with one of the variables so that the program throws an exception.
5. Comment each line of code you add to explain what you intend the code to do. Be sure to include a comment for the replacement value you added in Step 4 that causes the program to throw an exception.
6. Test and modify your Java™ program until it runs without errors and produces the results described above.
Note: Refer to this week's analyzing code assignment if you need help.
Submit your Java application file using the Assignment Files tab.

/********************************************************************
* Program:    PRG420Week5_CodingAssignment
* Purpose:       Week 5 Individual Assignment #2
* Programmer:    Iam A. Student
* Class:         PRG/420  PRG420 PRG 420
* Creation Date:   TODAY'S DATE GOES HERE
*********************************************************************
*
*********************************************************************
* Program Summary:
* This program converts a given date to a string.  
* The code includes exception handling for a ParseException.
************************************************************************************/
package prg420week5_codingassignment;
import java.util.*;
import java.text.*;
public class PRG420Week5_CodingAssignment {
 public static void main(String[] args){
  // The getInstance() method returns a Calendar object whose calendar fields have been initialized with the current date and time.
  Calendar calendar = Calendar.getInstance(); {
  LINE 1. BEGIN THE TRY BLOCK.
  String str_date="01-Nov-17"; // Declare a string that we will use later to format a date like this: ##-XXX-##
  DateFormat formatter; // Declare an object of type DateFormat so that we can call its parse() method later
  Date myFormattedDate; // Declare a variable of type Date to hold the formatted date
  formatter = new SimpleDateFormat("dd-MMM-yy"); // Assign a specific date format to the formatter variable
  // The given date is taken as a string that is converted into a date type by using
  // the parse() method
  myFormattedDate = (Date)formatter.parse(str_date); // setting up the format
  System.out.println("The formatted date is " + myFormattedDate);
  System.out.println("Today is " +calendar.getTime() );
  LINE 2. WRITE THE CATCH BLOCK TO CATCH EXCEPTIONS OF TYPE ParseException (TO HANDLE EXCEPTION, SIMPLY PRINT THE EXCEPTION)
  }
 }
}

Product Tags

Use spaces to separate tags. Use single quotes (') for phrases.