Results 1 to 3 of 3
  1. #1
    yanalvine is offline Member
    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0

    Default hello need help to correct my code

    designe a java class of person with the following attributes
    : person should have:
    1.Names
    a. First name
    b.Last name
    c. Middle initial
    d.ID number

    2. Date of birth
    a.Year of birth
    b.Month of birth
    c.Day of the month
    d. Day of the week


    import java.util.Scanner; // program uses class Scanner


    public class person {


    private String firstName;
    private String lastName;
    private String middleInitial;
    private String idNumber;


    public void personAttributes( String first, String last,String middle, String id )
    {

    firstName = first;
    middleInitial= middle;
    lastName = last;
    idNumber = id;



    // set first name
    public void setFirstName( String first )
    {
    firstName = first; // should validate
    } // end method setFirstName

    // return first name
    public String getFirstName()
    {
    return firstName;
    } // end method getFirstName

    // set last name
    public void setLastName( String last )
    {
    lastName = last; // should validate
    } // end method setLastName

    // return last name
    public String getLastName()
    {

    return lastName;
    } // end method getLastName

    // set social security number
    public void setIDNumber( String id )
    {
    idNumber = id; // should validate
    } // end method setSocialSecurityNumber

    // return social security number
    public String getIDNumber()
    {
    return IDNumber;
    } // end method getSocialSecurityNumber
    public class personAttributesTest
    {
    public void main( String[] args )
    {




    // get Person Attributes data
    System.out.println(
    "Person information obtained by get methods: \n" );
    System.out.printf( "%s %s\n", "First name is" );
    System.out.printf( "%s %s\n", "Last name is");
    System.out.printf( "%s %s\n", "Middle Initial is");
    System.out.printf( "%s %s\n", "ID number is" );


    } // end main
    } // end class personAttributesTest

    // create Scanner to obtain input from command window
    Scanner input = new Scanner( System.in );
    // Date class declaration.

    public class Date
    {
    private int month; // 1-12
    private int day; // 1-31 based on month
    private int year; // any year

    private static final int[] daysPerMonth = // days in each month
    { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

    // constructor: call checkMonth to confirm proper value for month;
    // call checkDay to confirm proper value for day
    public Date( int theMonth, int theDay, int theYear )
    {
    month = checkMonth( theMonth ); // validate month
    year = theYear; // could validate year
    day = checkDay( theDay ); // validate day

    System.out.printf(
    "Date object constructor for date %s\n", this );
    } // end Date constructor

    // utility method to confirm proper month value
    private int checkMonth( int testMonth )
    {
    if ( testMonth > 0 && testMonth <= 12 ) // validate month
    return testMonth;

    else // month is invalid
    throw new IllegalArgumentException( "month must be 1-12" );
    } // end method checkMonth

    // utility method to confirm proper day value based on month and year
    private int checkDay( int testDay )
    {
    // check if day in range for month
    if ( testDay > 0 && testDay <= daysPerMonth[ month ] )
    return testDay;

    // check for leap year
    if ( month == 2 && testDay == 29 && ( year % 400 == 0 ||
    ( year % 4 == 0 && year % 100 != 0 ) ) )
    return testDay;

    throw new IllegalArgumentException(
    "day out-of-range for the specified month and year" );
    } // end method checkDay

    // return a String of the form month/day/year
    public String toString()
    {
    return String.format( "%d/%d/%d", month, day, year );
    } // end method toString
    } // end class Date

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: hello need help to correct my code

    Do you have a question?

  3. #3
    Kuttappu's Avatar
    Kuttappu is offline Member
    Join Date
    Aug 2011
    Location
    Kerala, India
    Posts
    40
    Rep Power
    0

    Default Re: hello need help to correct my code

    According to question, i think they want you to design "Names" and "DateOfBirth" as inner classes for the class "Persons"

Similar Threads

  1. Very new to Java. Please help me correct my code.
    By jpab29 in forum New To Java
    Replies: 5
    Last Post: 06-29-2012, 05:05 PM
  2. Please correct this JSP code
    By rajesh4851 in forum New To Java
    Replies: 5
    Last Post: 06-13-2011, 01:12 PM
  3. Replies: 10
    Last Post: 06-06-2010, 11:12 AM
  4. Replies: 1
    Last Post: 10-24-2009, 03:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •