hello need help to correct my code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yanalvine
    New Member
    • Oct 2013
    • 8

    hello need help to correct my code

    Code:
    import java.util.Scanner; // program uses class Scanner
    import java.awt.Color;
    import java.awt.Graphics;
     import javax.swing.JPanel;
     
     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
    Last edited by Rabbit; Oct 17 '13, 05:29 AM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.
  • yanalvine
    New Member
    • Oct 2013
    • 8

    #2
    the question was:
    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

    Comment

    • chaarmann
      Recognized Expert Contributor
      • Nov 2007
      • 785

      #3
      That is not a question, that is your assignment description.
      So what is your question or problem with the code above?

      Comment

      • yanalvine
        New Member
        • Oct 2013
        • 8

        #4
        im getting errors i dont know why?

        Comment

        • chaarmann
          Recognized Expert Contributor
          • Nov 2007
          • 785

          #5
          Can you please post the error codes/messages here? Guessing them makes no sense.

          You are using scanner class. So we need to know what you povide as input, too. I mean the exact string that you have typed in.

          Comment

          • yanalvine
            New Member
            • Oct 2013
            • 8

            #6
            Description Resource Path Location Type
            IDNumber cannot be resolved to a variable person.java /helloe/src line 61 Java Problem
            Return type for the method is missing hi.java /helloe/src line 14 Java Problem
            smileButton cannot be resolved to a type hi.java /helloe/src line 14 Java Problem
            Syntax error on token ")", { expected after this token hi.java /helloe/src line 14 Java Problem
            Syntax error on token "smileButto n", VariableDeclara torId expected after this token hi.java /helloe/src line 14 Java Problem
            Syntax error, insert "}" to complete ClassBody person.java /helloe/src line 139 Java Problem
            Syntax error, insert "}" to complete MethodBody person.java /helloe/src line 23 Java Problem
            The public type test1 must be defined in its own file hi.java /helloe/src line 6 Java Problem
            This method requires a body instead of a semicolon hi.java /helloe/src line 11 Java Problem

            Comment

            • chaarmann
              Recognized Expert Contributor
              • Nov 2007
              • 785

              #7
              DNumber cannot be resolved to a variable person.java /helloe/src line 61 Java Problem
              See line 59 in program listing above:
              "IDNumber" is misspelled. You have defined "idNumber" in line 12. (lowercase I and D)

              Return type for the method is missing hi.java /helloe/src line 14 Java Problem
              smileButton cannot be resolved to a type hi.java /helloe/src line 14 Java Problem
              I can't see anything here. Have you removed the word "smileButto n" from the program listing after the error message was created, but before you copied the code here to the forum?
              ...

              General remark: put each of the classes in its own file. And the filename should the exact name of the file. There are inner classes, but it is an advanced topic, not suitable for beginner code.

              The other errors are about missing closing brackets. Just make sure that you always have a closing bracket for each opening bracket.

              Comment

              Working...