Driver
/**
* Write a description of class Driver here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.Arrays;
import javax.swing.JOptionPane;
public class Driver
{
public static void main(String[] args)
{
Birthday[] victim = new Birthday[10];
int[] day = new int[31];
String theName, theYear, theMonth;
String theDay;
String theGender;
String masterList = "";
int monthy, daily, yearly;
for(int x = 0; x<2; x++)
{
victim[x] = new Birthday();
theName = JOptionPane.showInputDialog("Please enter person #"+(x+1)+"'s name.");
theYear = JOptionPane.showInputDialog("Please enter the year of birth.");
theMonth = (String)(JOptionPane.showInputDialog(null, "Please choose the month of birth.", "Month chooser",JOptionPane.PLAIN_MESSAGE, null, Birthday.getMonths(), Birthday.getMonths(0)));
theDay = (String)(JOptionPane.showInputDialog(null, "Please choose the day of birth.", "Day chooser",JOptionPane.PLAIN_MESSAGE, null, Birthday.getDayTemp(), Birthday.getDayTemp(0)));
theGender = JOptionPane.showInputDialog("Please enter the student's gender (M or F).");
monthy = victim[x].setMonth(theMonth);
daily = victim[x].setDay(theDay);
yearly = victim[x].setYear(theYear);
victim[x] = new Birthday(theName, monthy, daily, yearly);
//victim[x].ageSet();
}
for(int x = 0; x<2; x++)
{
masterList = victim[x]+masterList;
}
String separator = "+++++++++++++++++++++++++++";
Arrays.sort(victim);
JOptionPane.showMessageDialog(null, masterList+"\n"+separator+"\n"+victim);
}
}
Birthday class
public class Birthday implements Comparable
{
private String name;
private int dayNum, monthNum, yearNum, age = 0;
private char sex;
private static String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
private static String[] dayTemp = {"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"};
public Birthday()
{
name = "Mr. Carlson";
dayNum = 20;
monthNum = 5;
yearNum = 1947;
char sex = 'M';
age = dayNum+monthNum*30+yearNum*365;
}
public Birthday(String newName, int newMonth, int newDay, int newYear)
{
name = newName;
monthNum = newMonth;
dayNum = newDay;
yearNum = newYear;
//sex = gender;
//age = monthNum*30+dayNum+yearNum*365;
}
public void setMonth(String theMonth)
{
for(int i = 0; i<12; i++) if(months[i].equals(theMonth)) monthNum = i+1;
}
public void setDay(String theDay)
{
for(int k = 0; k<31; k++) if(dayTemp[k].equals(theDay)) dayNum = k+1;
}
public void setYear(String theYear)
{
yearNum = Integer.parseInt(theYear);
//age = dayNum+monthNum*30+yearNum*365;
}
public void ageSet()
{
age = dayNum+monthNum*30+yearNum*365;
}
public int compareTo(Object o)
{
Birthday person = (Birthday) o;
if(person.yearNum==yearNum&&person.monthNum==monthNum&&person.dayNum==dayNum) return 0;
if(person.yearNum
return 1;
}
public static String[] getMonths()
{
return months;
}
public static String getMonths(int position)
{
return months[position];
}
public static String[] getDayTemp()
{
return dayTemp;
}
public static String getDayTemp(int where)
{
return dayTemp[where];
}
public String getName()
{
return name;
}
public int getDayNum()
{
return dayNum;
}
public int getMonthNum()
{
return monthNum;
}
public int getYearNum()
{
return yearNum;
}
public int getAge()
{
return age;
}
public String toString()
{
return name+": "+months[monthNum-1]+", "+dayNum+", "+yearNum;
}
}