More Java related...
-
Some java bean...basic stuff
/**
*
* Create a Java class that represents Students at a university. The attributes of Student are:
* First Name, Last Name, Middle Initial, Enrollment Date, Birthday, Sex, Major, Address, Telephone, Emergency Contact.
*
* The class file should also provide the following methods:
* getName(): returns the complete name, for example, John A. Smith
* getAge(): returns the student's age
* toString(): returns a string representation of the Student in whatever format that makes sense
*
*/
package com.ticketmap.useless;
import java.util.*;
/**
* @author Michael C
*
* a bean class
* TODO: USE A GOOD Eclipse plug-in to SAVE TIME!
*
* NOTE: C#'s way to do properties is BETTER and cleaner!
*/
public class Student
{
public enum Sex { male, female };
public enum Major { math, english }; //TODO add here...
protected String m_firstName="Michael",m_midInit="",m_lastName="Chen";
protected String m_street="",m_street2="",m_phone="",m_contact=""; // DO NOT start a new 'Address' class unless you plan to reuse it somewhere (e.g. faculty) or it has multiple 'address'
protected Sex m_sex = Sex.male;
protected Major m_major = Major.math;
protected GregorianCalendar m_enrllDate,m_birthDate;
public Student()
{
//TODO: create another 'helper' ctr for all properties
m_enrllDate = m_birthDate = new GregorianCalendar();
m_birthDate.set(Calendar.YEAR, 1964);
}
//TODO: Add all setters...
public void setFirst(String first)
{
m_firstName = first;
}
public void setLast(String last)
{
m_lastName = last;
}
public void setContact(String c)
{
m_contact = c;
}
//TODO: Add all getters...
public Sex getSex()
{
return m_sex;
}
public String getName()
{
return m_firstName.trim()+" " + (m_midInit.trim().length() > 0 ? (m_midInit+". ") : "")+ m_lastName;
// remove '.' when create
}
public int getAge()
{
return GregorianCalendar.getInstance().get(Calendar.YEAR) -
m_birthDate.get(Calendar.YEAR); // make sure m_birthDate was inserted valid
}
public String toString()
{
return getName()+", "+getAge()+" years old"; //, contact: "+m_contact;....
}
/**
* @param args
*/
public static void main(String[] args)
{
Student s = new Student();
s.setFirst("Dave");
//TODO set more .....
System.out.println("This dude is: "+s);
}
}