GFilde and Date class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • miss time
    New Member
    • Jun 2007
    • 16

    #1

    GFilde and Date class

    Hi
    please tell me the wrong in this code becaus it not compile with me
    the question depend in other class that i do it before
    and this class her:
    public class GField
    {
    private int value;
    private int minimum;
    private int maximum;
    private int defu;



    public GField(int v,int m,int x,int def){
    if (v>minimum && v<maximum) value=v;
    else value=1;
    value = v; minimum= m; maximum =x;
    defu=def;
    }

    public int getV(){
    return value;}
    public int getM(){
    return minimum;}
    public int getX(){
    return maximum;}

    public void setV( int v){
    if (v>minimum && v<maximum) value=v;
    else value=1;
    value = v;
    }
    public void setM( int m)
    {
    minimum= m;}
    public void setX( int x)
    {
    maximum= x;}
    but the other question is
    2- Date class: this class has day, month, and year fields. All fields must be defined privates and all fields are of type GField defined above.
    a. Provide a default constructor in which you set the date to 1/1/2000.
    b. Provide a constructor that takes 3 integer parameters for the 3 fields.
    c. Provide a constructor that takes 2 integer parameters for the day and month. The constructor should set the year to 2007.
    d. Provide only getters for each field.
    e. Provide the toString method such that it returns a string representation of the date in the form DD/Month/YYYY, e.g, (12/November/1990)
    f. Write a method that returns the name of the month. For example, if the month is 3 it will returns "march".
    g. Make sure that each field holds correct values. Specifically, month should be between 1 and 12 and day should be between 1 and 31. In case the user provided invalid day or month then you need to save a valid value instead as follows:
    i. If the user provides a month which is not between 1 and 12, then set it with |(N % 12) + 1|.
    ii. For days, if the user provides a day which is not between 1 and 31 then set it with the value | (N % 31) + 1|.
    and i try to do it but it is not compile please tell me the wrong and this cod i wrote it.
    public class Date1
    {
    private GField day;
    private GField month;
    private GField year;
    public Date1(){
    day=1;
    month=1;
    year=2000;
    }
    public Date1 ( GField D, GField M, GField Y){
    if(M<=12 && M>=1) month=M;
    else m=abs((N % 12) + 1) ;
    if (D>=1 && D<=31) day=D;
    else day=abs ((N % 31) + 1);
    ;

    year= Y;
    }
    Date1( GField D, GField M){
    day= D;
    month=M;
    year=2007;
    }
    GField getDay(){
    return day;
    }

    GField getMonth(){
    return month;
    }

    GField getYear(){
    return year;
    }
    public String toString(){
    return day + "/" + month + "/" + year;
    }
    public String getName(){
    if (m==1) return "Jan";
    if (m==2) return "november";
    if (m==3) return " march";
    if (m==4) return "Apr";
    if (m==5) return "May";
    if (m==6) return "JUN";
    if (m==7) return "july";
    if (m==8) return "Augest.";
    if (m==9) return "Septemr";
    if (m==10) return "october";
    if (m==11) return "Nov";
    else return "DEC";
    }
    }
    Sorry if the question is too long and i hope who know the question explen to me the step of do this question
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by miss time
    Hi
    please tell me the wrong in this code becaus it not compile with me
    And what does the compiler whine about then? The Java compiler does all its
    best to whine as detailed as possible. Please show us what it whined about.

    kind regards,

    Jos

    Comment

    • miss time
      New Member
      • Jun 2007
      • 16

      #3
      Originally posted by JosAH
      And what does the compiler whine about then? The Java compiler does all its
      best to whine as detailed as possible. Please show us what it whined about.

      kind regards,

      Jos
      thank you very much....sorry but i dont understand what you mean. I will explain to you my problem. when i compile the Date1 class ,it does not compile and her i use (Bluej) and it tell me that day=1; is wrong and the reason is( incompatible types-found (int) but expected GField). i hope that what you mean .and thank you again for your help^_^

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by miss time
        thank you very much....sorry but i dont understand what you mean. I will explain to you my problem. when i compile the Date1 class ,it does not compile and her i use (Bluej) and it tell me that day=1; is wrong and the reason is( incompatible types-found (int) but expected GField). i hope that what you mean .and thank you again for your help^_^
        Like the compiler said, you declared day as a variable of type GFied and so you must store only GField type objects in it.

        Comment

        Working...