Question: This is written in Java. The instructions given were: Change this code as much as you can to produce the same results. In the new

This is written in Java. The instructions given were: Change this code as much as you can to produce the same results. In the new code do not use the GregorianCalendar. Write it in Java.

import java.text.DateFormat; import java.util.Date; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.GregorianCalendar; public class Entry {

public String x; Date startDate; Date endDate;

String[] find; String[] summary;

public Entry(String line) throws Exception { x = line; DateFormat form = new SimpleDateFormat("Y-M-D H:M");

find = new String[10]; summary = new String[6]; String[] sep = line.split(",");

for(int i=0; i<10; i++){ find[i] = new String(sep[i]); }

for(int i=0; i<6; i++) summary[i] = new String(sep[20+i]);

String toParse = sep[0].substring(0, 4) + "-" + sep[0].substring(4, 6) + "-" + sep[1]; Integer no = Integer.parseInt(sep[2]); toParse += " " + no/100 + ":" + no%100; try{ startDate = form.parse(toParse); } catch(Exception e){ System.exit(1); }

//System.out.println(startDate); toParse = sep[3].substring(0, 4) + "-" + sep[3].substring(4, 6) + "-" + sep[4]; no = Integer.parseInt(sep[5]); toParse += " " + no/100 + ":" + no%100; try{ endDate = form.parse(toParse); } catch(Exception e){ System.exit(1); } }

public boolean isTime(Integer year){ Calendar cal = new GregorianCalendar();

cal.setTime(startDate); if(cal.get(Calendar.YEAR) == year) return true; cal.setTime(endDate); if(cal.get(Calendar.YEAR) == year) return true;

return false; }

public String[] getSummary(){ return summary; }

public String[] getFind(){ return find; }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!