Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: sumone help me with y code

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default sumone help me with y code

    i am studying java at home and using online forums and resources (course fees too expensive)
    i recently came across some assignment and i have been trying to do it to no avail.
    can someone please help me with a few stages.
    basically ive completed first two stages (classes) and the third stage involves inheritance and designing a third "student" and "part time" that inherits from "class person"

    class date

    public class Date
    {
    private int day, month,year;

    public Date(int dd, int mm, int yy)
    {
    day=dd;
    month=mm;
    year=yy;
    }
    public Date(Date other)
    {
    this(other.day,other.month,other.year);
    }

    public boolean equals (Date other)
    {
    return day==other.day && month==other.month &&
    year==other.year;
    }


    public void copy(Date other)
    {
    day=other.day;
    month=other.month;
    year=other.year;

    }
    public String monthAsString()
    {
    switch (month)
    {
    case 1: return "JANUARY";
    case 2: return "FEBUARY";
    case 3: return "MARCH";
    case 4: return "APRIL";
    case 5: return "MAY";
    case 6: return "JUNE";
    case 7: return "JULY";
    case 8: return "AUGUST";
    case 9: return "SEPTEMBER";
    case 10: return "OCTOBER";
    case 11: return "NOVEMBER";
    case 12: return "DECEMBER";
    default: return "error";
    }
    }
    public boolean lessThan(Date other)

    {

    if (year < other.year)

    return true;

    else if (year > other.year)

    return false;

    else if (month < other.month)

    return true;

    else if (month > other.day)

    return false;

    else if (day< other.day)

    return true;

    else if (day >= other.day)

    return false;
    else return true;

    }



    public String toString ()

    {
    return "day" +day+ "month" + month + "year" + year;
    }
    }

    and class person

    public class Person

    {

    protected String name;
    protected String gender;
    protected Date dateOfBirth;
    protected String address;
    protected String natInsceNo;
    protected String phoneNo;
    protected static int counter;

    public Person()
    {
    name="";
    gender="";
    natInsceNo="";
    phoneNo="";
    counter++;
    }

    public Person (String nme, char sex, Date dob)
    {
    dateOfBirth = new Date(dob);
    setGender(sex);
    name = nme;
    address ="";
    counter++;
    } //end constructor

    public Person(Person other)


    {
    name = other.name;
    dateOfBirth = other.dateOfBirth;
    gender = other.gender;
    address = other.address;
    natInsceNo = other.natInsceNo;
    }


    public String getname()

    {
    return name;
    }

    public void setGender (char gen)
    {
    if (gen == 'm' || gen == 'M')
    gender = "male";
    else if (gen == 'f' || gen == 'F')
    gender = "female";
    else System.out.println("unknown");
    }

    public static int count()
    {
    return counter;
    }
    public String getAddress()
    {
    return address;
    }
    public Date dob()
    {
    return dob();
    }
    public String natInsceNo()
    {
    return natInsceNo;
    }
    public String phoneNo()
    {
    return phoneNo;
    }
    public void copy(Person other)
    {

    name = other.name;
    dateOfBirth = other.dateOfBirth;
    address = other.address;
    natInsceNo = other.natInsceNo;
    gender = other.gender;
    }

    public boolean equals(Person other)
    {
    return dateOfBirth.equals(other.dateOfBirth) && natInsceNo.equals(other.natInsceNo) &&
    dateOfBirth.equals(other.dateOfBirth);
    }
    public void setAddress(String newAddress)
    {
    address = newAddress;
    }

    }

    i now need a third class "student" that inherits from class person and a "class part time" that also inherits from "class person"
    showing
    protected variables
    dateEnrolled //Date
    course // String
    year // int
    constructor
    Student()
    // post variables set to non-null values;
    Student (String nme, char sex, Date dob,
    String insceNumber, Date enrolled)
    // pre dob != null enrolled != null
    // post variables initialised with params passed in
    Note that both these constructors should also call the
    inherited constructor.
    The clone constructor should also call the inherited constructor;
    transformers
    void setCourse(String s)
    // pre s is not null
    // post course is set to s
    void setYear(int yr)
    // 0 < yr
    // post year is set to yr
    Note that the copy should also call the inherited copy
    accessors
    No additional ones specified.
    The toString() method should also call the inherited toString.
    There is no need for a new equals method for this class.

    AND

    Design and code class PartTime, which inherits from Student.
    protected variables
    employer // String
    workAddress // String
    workPhoneNo // String
    constructor
    PartTime()
    // post variables set to non-null values;
    PartTime (String nme, char sex, Date dob,
    String insceNumber, Date enrolled)
    // pre dob != null enrolled != null
    // post variables initialised with params passed in
    Note that both these constructors should also call the
    inherited constructor.
    The clone constructor should also call the inherited constructor;
    transformers
    void setEmployer(String emp)
    // pre emp is not null
    // post employer is set to emp
    void setWorkAddress(String wAddr)
    // pre wAddr is not null
    // post workAddress is set to wAddr
    void setWorkPhone(String wPhone)
    // pre wPhone is not null
    // post workPhone is set to wPhone
    Note that the copy should also call the inherited copy
    accessors
    No additional ones specified.
    The toString() method should also call the inherited toString().
    There is no need for a new equals method for this class.


    SOMEONE HELP ME IM STUCK! im supposed to follow this with a "class store" etc but im fine with those just these last two steps are worrying!


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: sumone help me with y code

    I recommend you read the link in my signature on asking questions the smart way, as well as this: Inheritance (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Oct 2011
    Posts
    40
    My Mood
    Stressed
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: sumone help me with y code

    As it stands, your code is undreadable. Please edit and add java tags around it. [ highlight=Java] your code [/highlight]. remove the space before highlight=Java to get them to work.
      your code

Similar Threads

  1. describe this program code by code ....
    By izzahmed in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 29th, 2011, 11:03 PM

Tags for this Thread