Hi
I'm having a bit of a problem with my code. It's not outputting the desired output that I want.
I plan to use this array to test the output that I want.
private String[][] TEST_DATA = {
{ "1", "TaskTracker", "Clear doesn't clear the title", "Closed", "Alex",
"Bug", "1.0", "1 - Must Fix", "22-6-2005", "1 day", "Sam",
"3-6-2005", "..." },
{ "2", "TaskTracker", "Icons need to be cleaned up", "Active", "Unassigned",
"Improvement", "1.0", "1 - Must Fix", "22-6-2005", "", "Gary",
"3-6-2005", "" },
{ "3", "TaskTracker", "Add undo", "Active", "Unassigned",
"Feature", "1.0", "3 - Fix if time", "22-6-2005", "", "Gary",
"3-6-2005", "" }, };
Here's my code, it has 3 classes:
This class is used as the main method for the output of the arrays
package labs;
import java.text.DateFormat;
import java.util.*;
import util.DateUtil;
import util.GregorianCalendar;
import data.Task;
public class Lab2
{
private String[][] TEST_DATA = {
{ "1", "TaskTracker", "Clear doesn't clear the title", "Closed", "Alex",
"Bug", "1.0", "1 - Must Fix", "22-6-2005", "1 day", "Sam",
"3-6-2005", "..." },
{ "2", "TaskTracker", "Icons need to be cleaned up", "Active", "Unassigned",
"Improvement", "1.0", "1 - Must Fix", "22-6-2005", "", "Gary",
"3-6-2005", "" },
{ "3", "TaskTracker", "Add undo", "Active", "Unassigned",
"Feature", "1.0", "3 - Fix if time", "22-6-2005", "", "Gary",
"3-6-2005", "" }, };
public Lab2()
{
}
public static void main(String[] args)
{
DateUtil date = new DateUtil();
System.out.println(new Lab2().test());
//System.out.println(date.Storage());
}
public String test()
{
DateUtil date = new DateUtil();
Task first = new Task(TEST_DATA[0]);
Task second = new Task(TEST_DATA[1]);
Task third = new Task(TEST_DATA[2]);
String n;
//n = DateFormat.getDateInstance().format(date.Convert(num));
Task []display = {first, second, third};
return Arrays.toString(display);
}
}
second class is used to hold the variables and return them
package a00620524.data;
import java.util.GregorianCalendar;
import util.DateUtil;
public class Task
{
private int caseNumber;
private String project;
private String title;
private String status;
private String assignedToName;
private String category;
private String fixForVersion;
private String priority;
private GregorianCalendar dueDate;
private String estimate;
private String openedBy;
private GregorianCalendar openedDate;
private String notes;
public Task()
{
}
//To hold the strings in the constructor
public Task(String[] arrayset)
{
caseNumber = Integer.parseInt(arrayset[0]);
project = arrayset[1];
title = arrayset[2];
status = arrayset[3];
assignedToName = arrayset[4];
category = arrayset[5];
fixForVersion = arrayset[6];
priority = arrayset[7];
dueDate = DateUtil.Convert(arrayset[8]);
estimate = arrayset[9];
openedBy = arrayset[10];
openedDate = DateUtil.Convert(arrayset[11]);
notes = arrayset[12];
}
/**
*
* @return
* @author
*/
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("Task[");
buffer.append("assignedToName = ").append(assignedToName);
buffer.append(" caseNumber = ").append(caseNumber);
buffer.append(" category = ").append(category);
buffer.append(" dueDate = ").append(dueDate);
buffer.append(" estimate = ").append(estimate);
buffer.append(" fixForVersion = ").append(fixForVersion);
buffer.append(" notes = ").append(notes);
buffer.append(" openedBy = ").append(openedBy);
buffer.append(" openedDate = ").append(openedDate);
buffer.append(" priority = ").append(priority);
buffer.append(" project = ").append(project);
buffer.append(" status = ").append(status);
buffer.append(" title = ").append(title);
buffer.append("]");
return buffer.toString();
}
public String getAssignedToName() {
return assignedToName;
}
public void setAssignedToName(String assignedToName) {
this.assignedToName = assignedToName;
}
public int getCaseNumber() {
return caseNumber;
}
public void setCaseNumber(int caseNumber) {
this.caseNumber = caseNumber;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public GregorianCalendar getDueDate() {
return dueDate;
}
public void setDueDate(GregorianCalendar dueDate) {
this.dueDate = dueDate;
}
public String getEstimate() {
return estimate;
}
public void setEstimate(String estimate) {
this.estimate = estimate;
}
public String getFixForVersion() {
return fixForVersion;
}
public void setFixForVersion(String fixForVersion) {
this.fixForVersion = fixForVersion;
}
public String getNotes() {
return notes;
}
public void setNotes(String notes) {
this.notes = notes;
}
public String getOpenedBy() {
return openedBy;
}
public void setOpenedBy(String openedBy) {
this.openedBy = openedBy;
}
public GregorianCalendar getOpenedDate() {
return openedDate;
}
public void setOpenedDate(GregorianCalendar openedDate) {
this.openedDate = openedDate;
}
public String getPriority() {
return priority;
}
public void setPriority(String priority) {
this.priority = priority;
}
public String getProject() {
return project;
}
public void setProject(String project) {
this.project = project;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
The third is used to convert and format the dates to 27-11-2005 and Jun 3, 2005
package util;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.StringTokenizer;
import java.text.DateFormat;
public class DateUtil
{
Calendar calendar;
static GregorianCalendar g;
static int d;
static int m;
static int y;
public DateUtil()
{
}
//static is chosen so all can output the same thing
public static GregorianCalendar Convert(String num)
{
StringTokenizer token = new StringTokenizer(num, "-");
d = Integer.parseInt(token.nextToken());
m = Integer.parseInt(token.nextToken());
y = Integer.parseInt(token.nextToken());
g = new GregorianCalendar(y, m, d);
return g;
}
public String Reformat()
{
calendar = new GregorianCalendar();
String jan = "Jan";
String feb = "Feb";
String march = "Mar";
String april = "Apr";
String may = "May";
String june = "Jun";
String july = "Jul";
String aug = "Aug";
String sept = "Sept";
String oct = "Oct";
String nov = "Nov";
String dec = "Dec";
if(calendar.get(Calendar.MONTH) == Calendar.JANUARY)
return jan;
if(calendar.get(Calendar.MONTH) == Calendar.FEBRUARY)
return feb;
if(calendar.get(Calendar.MONTH) == Calendar.MARCH)
return march;
if(calendar.get(Calendar.MONTH) == Calendar.APRIL)
return april;
if(calendar.get(Calendar.MONTH) == Calendar.MAY)
return may;
if(calendar.get(Calendar.MONTH) == Calendar.JUNE)
return june;
if(calendar.get(Calendar.MONTH) == Calendar.JULY)
return july;
if(calendar.get(Calendar.MONTH) == Calendar.AUGUST)
return aug;
if(calendar.get(Calendar.MONTH) == Calendar.SEPTEMBER)
return sept;
if(calendar.get(Calendar.MONTH) == Calendar.OCTOBER)
return oct;
if(calendar.get(Calendar.MONTH) == Calendar.NOVEMBER)
return nov;
if(calendar.get(Calendar.MONTH) == Calendar.DECEMBER)
return dec;
return "Month: unknown";
}
public String Storage()
{
DateUtil date = new DateUtil();
calendar = new GregorianCalendar();
int day;
int yr;
String mon;
String output;
//the month is a String
mon = date.Reformat();
//the year and date are integers
day = calendar.get(Calendar.DATE);
yr = calendar.get(Calendar.YEAR);
//outputs the string of the month, day, and year
output = mon + " " + day + ", " + yr;
return output;
}
}
Message was edited by:
vopo
Message was edited by:
vopo
null