Organize the code capable of throwing

Assignment Help Basic Computer Science
Reference no: EM132013064

How would you code the following in Java when given the coding below?

-Organize the code capable of throwing an exception of type ParseException as a try block.

-Include a catch block to handle a ParseException error thown 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.

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. DD THE CATCH BLOCK TO CATCH EXCEPTIONS OF TYPE ParseException (TO HANDLE EXCEPTION, SIMPLY PRINT THE EXCEPTION)

Reference no: EM132013064

Questions Cloud

Identify the life-span time period between given age : Zastrow and Kirst-Ashman, use the term young and middle adulthood to identify the life-span time period between age 18 and 65. This classification distinguishes
Advantage and disadvantage for web-dbms integration : List at lest at least 5 items for advantage and disadvantage for Web-DBMS integration. Please point out the main reason for each items.
What do twin and adoption study tell about effect of nature : What do twin and adoption studies tell us about the effects of nature (i.e., genetic influences) and nurture (i.e., environmental influences).
Defined a variable ptr of type unsigned short : CMPT 214: Programming Principles and Practice Assignment. Suppose that in this program there is also defined a variable ptr of type unsigned short *
Organize the code capable of throwing : -Organize the code capable of throwing an exception of type ParseException as a try block.
Four locations hooked up to the internet : What were the first four locations hooked up to the Internet (ARPANET)? Which came first, the Internet or the World Wide Web?
How nutrition needs change throughout the lifecycle : Describes how nutrition needs change throughout the lifecycle and identifies ways to improve an individual's nutritional intake.
Various approaches of implementing databases internet : The approach to implement database Internet connectivities. search for various approaches of implementing databases Internet
Describe adonet and fusion middleware : Describe ADO.Net and Fusion Middleware, and then compare the pros and cons between these 2 approaches.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd