Return the number of days in the month represented by thisSimpleDate. Return the
ID: 3613099 • Letter: R
Question
Return the number of days in the month represented by thisSimpleDate.
Return the day represented by this SimpleDate.
Return the month represented by this SimpleDate.
Return a short string representation of this SimpleDate object. Ashort string representation will have the format: MM/DD/YYYY. Forexample 3/15/2002 or 10/5/1987.
Return the year represented by this SimpleDate.
For this lab we assume February always has 28 days: there are noleap years.
Your class should support the following constructors:
Construct a new SimpleDate object with the day=1, month=1 andyear=initYear.
Construct a new SimpleDate object with the day=1, month=initMonthand year=initYear. If an invalid value is provided for the monthits value should default to 1.
Construct a new SimpleDate object with the day=initDay,month=initMonth and year=initYear. If invalid values are providedfor the day or the monththen both month and day should be set to1.
There is no default constructor. Write a driver class Driver.javawhich declares and uses SimpleDate objects in a way that tests thefunctionality of the class methods.
Explanation / Answer
please rate - thanks output line number 1 is the date input, lines 2-7 show the errorsand different constructors sample run ----jGRASP exec: java Driver Enter date to convert example-May 5, 2009 August 2, 2009 1 8/2/2009 2 8/1/2009 3 1/1/2009 4 1/1/2009 5 1/1/2009 6 8/1/2009 7 1/1/2009 ----jGRASP: operation complete. program import java.util.*; class Driver{ public static void main(String[] args) { int pos,pos2,day,year,i,month; String[] months={"january","february","march","april","may","june","july", "august","september","october","november","december"}; String input,monthin; Scanner in=new Scanner(System.in); System.out.println("Enter date to convertexample-May 5, 2009 "); input=in.nextLine(); pos=input.indexOf(' '); monthin=(input.substring(0,pos).trim()).toLowerCase(); //extract month & make lower case // System.out.println(monthin); pos2=input.indexOf(','); day=Integer.parseInt(input.substring(pos+1,pos2).trim()); //extract day // System.out.println(day); year=Integer.parseInt(input.substring(pos2+1,input.length()).trim()); //extract year //System.out.println(year); month=1; for(i=0;iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.