Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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)

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M92850712
  • Price:- $15

Priced at Now at $15, Verified Solution

Have any Question?


Related Questions in Computer Engineering

Please discuss the design principles that guide the authors

Please discuss the design principles that guide the authors of instruction sets in making the right balance. Provide examples of application of each of the three design principles while designing instruction sets.

The socket example of pages 130 and 131 of the os-book

The Socket example of pages 130 and 131 of the OS-Book (Abraham Silberschatz 8th edition) is the basis of this problem. However, instead of using the Loopback IP (127.0.0.1), which emulates the socket connection on the h ...

A new machine averages 4 clock cycles per instruction and

A new machine averages 4 clock cycles per instruction, and runs at a system clock of 20 MHz. The Axiom-Verge algorithm set to benchmark the system will take an even 3000 instructions to complete. a) Knowing how many cloc ...

Task define a class bubble with data members static int

Task : Define a class Bubble with data member's static int objCount and 2D integer array mat [10] [10] and 2 integer members rows and cols. Define a default constructor which will increment objCount when an object is cre ...

Need help with the following 2 problems1 they offer you a

Need help with the following 2 problems: 1. They offer you a promissory note with a four-year maturity, which will generate $ 3,000 at the end of each of the four years. Its price is $ 10,200. What is the implicit annual ...

Smartphones have become an important part daily life

Smartphones have become an important part daily life, including how we communicate in business. Mobile device security is emerging as one of top targets for cybercriminals. Using Microsoft Word, write a 400 word paper us ...

Systems analysis project personal trainer inc owns and

Systems analysis project Personal Trainer, Inc. owns and operates fitness centers in a dozen Midwestern cities. The centers have done well, and the company is planning an international expansion by opening a new "superce ...

Why hasnt health care in australia been entirely privatised

Why hasn't health care in Australia been entirely privatised, according to Boxall and Gillespie? Should health care (in Australia) be wholly privatised? Do you think it will be in the future?

What effect does the teacher have on creating a learning

What effect does the teacher have on creating a learning environment with little to no behavior problems?

A mining company wishes to start up a new small gold mine

A mining company wishes to start up a new small gold mine. The initial cost will be $5m and it is expected to extract $3m a year in gold with incurring only $1.5m a year in costs for 5 years. Assume revenue and costs are ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As