Jump to content

Date Of Birth Revision , Class please help

- - - - -

  • Please log in to reply
4 replies to this topic

#1
youssef22

youssef22

    Newbie

  • Members
  • Pip
  • 1 posts
hi i am studying computer science within my first year of university. i am completly new to java programming, and would please some help regarding this revision source i have been givien by my tutor. i need some pointers on how to start this. as seen below

can someone give me a slight example of how i would start this please. in plain english explaining which is which, i know nothing of java and have only just started university and keen to progress im just finding this a little hard please. im have to use a program called eclipse.

thank you much appreciated

p.s. i have had some pointers on some java through out this website but is kinda hard to get into the mind i have also brought books too , so apologies on behalf this and would appreciate the help. thankyou ever so much . the sources can be seen below.

the scenario


Posted Image


diagram


Posted Image



Question


Posted Image

sorry about this. i am using a program called eclipse how would i start and solve this. would like this as revision so i can look at back at it . please thank you ever so much.

Edited by ZekeDragon, 30 October 2010 - 03:27 AM.


#2
so1i

so1i

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 312 posts
I have also just started first year Comp Sci. I have a done a fair bit of java before, but still the UML style of representing program structures is still quite new to me (just giving an excuse in case I make a mistake xD)

Basically, each of the boxes is a class, the arrows show where they inherit things from. So what I would do to start this is set up the basic outlines of the program-the different classes, then the methods defined in each class appropriately.

Again, I am studying this myself at the moment, so it may not be quite right, but I would start it as follows:

public class email {
//contents of class here, including a constructor, the attributes and methods specific to this class
}

Not sure if that gives you enough to get you going, or if in fact I'm going about it the right way. Maybe some one else can help!

Btw, welcome to the forums. Whereabouts are you from? I'm at University in the UK at the moment... hope you are liking comp sci!

so1i
My Company - My Homepage - My Twitter - My Google+ - My LinkedIn

"Things don’t have to change the world to be important.” - Steve Jobs

#3
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
As so1i said every box is a class in Java. Each box consists of 3 sections:
  • top: class name. A class name as it stands there is a normal class. If it's in italic it indicates it's an abstract class. Interfaces are usually shown by putting <<interface>> above the name.
  • middle: variables
  • methods
The notation for variables and methods are kinda equal. It always(usually) has a -, + or # in front of it.
- means private
+ means public
# means protected

Unlike Java all the types are behind the name of the variables / method
The 'in' keyword at the method parameter can basicly be ignored.

Note that getters, setters and constructors don't have to be shown on the diagram. It doesn't mean that they aren't shown there they don't appeir in the actual code.

Judging by the diagram, the email class will look as followed:
Since it's a 0..1 relation between email and user i would put a user reference in email.
My guts tell me to put Email in user, the other way around, but since emails can exist without having a user (weird, even weirder with the birthdate) according to the diagram i guess it's better this way.


public class Email{

  private String emailAddress;

  private User user;


  private boolean validateEmailAddress( String emailAddress){

     //pseudocode

     if(emailAddress.isvalid() ){

        return true;

     } else {

        return false

     }

     //end of pseudocode

  }


  public String getEmailAddress(){

    return emailAddress

  }


}



#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
You posted another question like this earlier and were given an example, can you come up with a basic outline of the class yourself before we can help you? You may not learn much otherwise I am afraid.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#5
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
I don't mean to sound harsh or anything, but your instructor has provided you everything you really need to know to write this project assuming you know how to write a basic class in Java, which you should. Assuming you don't however, I'll show you:
public class MyClass  // This is the class declaration!
{
    public MyClass(int argument)
    /* This is a constructor. When a new object of MyClass is instantiated, there is sometimes a bunch of
       information your class will need (for example, in your DateOfBirth object you'd need three ints or
       a string to represent a date) in order to create the object. This method does that. */
    {
        this.value = argument;
    }

    public int getValue()  // This is a method declaration and definition.
    {
        return this.value;
    }

    private int value;  // This is a private property of the MyClass object.
}
So, I think what Nullw0rm asks isn't too difficult, provide some initial effort with a class of your own writing. It doesn't even need to do anything, nor certainly not have the validating code, we'll help you with those as they come up, but until then just try and write a DateOfBirth object that would have values representative of a date of birth and methods to get these values. Or try writing the User object with a hypothetical DateOfBirth and Email objects (this is called "Wishful Thinking" in parlance, it's actually not a bad thing in this context), either way don't be afraid to put something on the table.

NOTE: I merged your threads, don't post repeat content.
Wow I changed my sig!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users