Write the missing code in the below program. A calendarDemo class is created with a setTime method which passes one argument. SimpleDateFormat is used to parse the string and produce the date. Calendar setTime method is used to set time to the value of date.

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter10: Object-oriented Programming
Section: Chapter Questions
Problem 13RQ
icon
Related questions
Question

Write the missing code in the below program. A calendarDemo class is created with a setTime method which passes one argument. SimpleDateFormat is used to parse the string and produce the date. Calendar setTime method is used to set time to the value of date.

Epected Output

Setting·to·the·new·time·Feb-09-2012

 

DRIVER CODE

package q11589;
import java.util.*;
import java.text.SimpleDateFormat;
import java.text.ParseException;
public class CalendarDemoMain {
    public static void main(String ... args) {
        String date = args[0];
        CalendarDemo c = new CalendarDemo();
        try {
        String date2 = c.setTime(date);
        System.out.println("Setting to the new time " + date2);
        }
        catch(ParseException pe) {
            System.out.println("You used the wrong format in SimpleDateFormat");
        }
    }
}

 

CHANGE IN THIS CODE 

 

package q11589;
import java.util.*;
import java.text.SimpleDateFormat;
import java.text.ParseException;
public class CalendarDemo {
    public String setTime(String dateString) throws ParseException {
        // use the correct format string as argument for the constructor
        SimpleDateFormat sd = new SimpleDateFormat("");
        
        // parses text from the beginning of the given string to produce a date
        Date date =  sd.parse(dateString);
        
        
        Calendar currentTime = Calendar.getInstance();
        
        //// configuring the current object to the value of date
        currentTime.setTime(date);
        
        // format method on SimpleDateFormat returns a string representation of the passed date
        return sd.format(currentTime.getTime());
    }
}
        
        

 

 

 

 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage