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 11 of 11

Thread: HELP!!! Entry Class to represent entries in a telephone directory

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Location
    North Wales
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry HELP!!! Entry Class to represent entries in a telephone directory

    I have to create a java file to do

    Write a class Entry which represents entries in a telephone directory. Each entry consists of a name an address a telephone number
    Represent all three items as single strings.
    public class Entry
    {
    String name;
    String address;
    String telNo;
    . . .
    }
    Provide appropriate constructors and methods for this class. This will involve providing getters and setters for each instance variable as well as a toString() method.

    I have NO clue what I am doing! And this is what I have so far!

    public class Entry 
     
    {
     
    public static void main(String[] args){
     
    	Entry e =  new Entry("Corky", "DH 3104", "x 6042");
    e.getName();
    e.getAddress();
    e.getPhone();
     
     
     
      /* fields */ 
      String name;	
      String address;
      String phone;
     
      /* constructor */
      Entry(String n, String a, String p) {
        this.name = n;
        this.address = a;
        this.phone = p;
      }	 	 
     
      /* accessors */
      String getName() { return this.name; }
      String getAddress() { return this.address; }
      String getPhone() { return this.phone; }
     
    }
    Last edited by Freaky Chris; January 19th, 2010 at 10:03 PM.


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: HELP!!! Entry Class to represent entries in a telephone directory

    Another Bangor university student drops by, hi.

    Who are you, might I ask?

  3. #3
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: HELP!!! Entry Class to represent entries in a telephone directory

    You are most definitely on the right track there. There might be other appropriate constructors that you could create as well, maybe one that takes a name and a phone number only because some people might not want to have their address listed for instance.

    You also need to add the setter methods for name, address and phone number.

    public void setName(final String name) {
        this.name = name;
    }

    This way you can change the data of one entry even after you have created the object.

    I think you might be missing a closing bracket for the main method as well.

    // Json

  4. #4
    Junior Member
    Join Date
    Jan 2010
    Location
    North Wales
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: HELP!!! Entry Class to represent entries in a telephone directory

    Where would I put

    public void setName(final String name) {
    this.name = name;
    }

    Sorry Im a complete beginner at this!

    @Chris, Hiiii, Yes another Bangor University Student how did you guess? My name is Dana
    Last edited by Princess D; January 20th, 2010 at 09:47 AM.

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: HELP!!! Entry Class to represent entries in a telephone directory

    Anywhere inside of your Entry class is fine, as long as it isn't inside of any other methods and no other methods/field declarations are inside of it.
    public class Entry
    {
         // all of the code you had in here previously
     
         public void setName(final String name) {
         {
              this.name = name;
         }
    }

  6. #6
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: HELP!!! Entry Class to represent entries in a telephone directory

    Quote Originally Posted by Princess D View Post
    Where would I put

    public void setName(final String name) {
    this.name = name;
    }

    Sorry Im a complete beginner at this!

    @Chris, Hiiii, Yes another Bangor University Student how did you guess? My name is Dana
    Easy, i've seen a few people post this assignment and beleive it or not I have had to do it myself lol! At least you are admitting you are from bangor and not being afraid of the fact someone found them out. Unfortunately I can't really help for fear of braking some form of plagurism, if thats how you spell it

    I also see you're an avid web developer, might i ask is the web developer or web designer?

    Chris

  7. #7
    Junior Member
    Join Date
    Jan 2010
    Posts
    7
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: HELP!!! Entry Class to represent entries in a telephone directory

    Here you go cleaned up a little

    public class Entry 
    {
     
    	private String name;
    	private String address;
    	private String telno;
     
    	//Default Constructor
    	public Entry()
    	{
     
    	}
     
        public Entry(String aName, String aAddress, String aTelno)
        {
           this.name = aName;
           this.address = aAddress;
           this.telno = aTelno;
        }
     
    	public void setName(String name) {
    		this.name = name;
    	}
     
    	public String getName() {
    		return name;
    	}
     
    	public void setAddress(String address) {
    		this.address = address;
    	}
     
    	public String getAddress() {
    		return address;
    	}
     
     
    	public void setTelno(String telno) {
    		this.telno = telno;
    	}
     
    	public String getTelno() {
    		return telno;
    	}
     
    }

    Of course make sure you look at all the requirements for this entity.
    Will you need to be able to look up numbers by different parts? In the US we have Country-Area-Nxx-#### format of our numbers - so the PhoneNumber field as a single string is only usable for output. In our code we actually store country, area and the nxx-#### separate in our database and have to make sure our entities understand that.
    Also, typically we have to separate names in First, Middle, Last, Title, etc... but this is probably beyond the scope of your assignment. Many years of working on CRM apps have made me overly detailed about this stuff! Hope this help!

  8. #8
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: HELP!!! Entry Class to represent entries in a telephone directory

    The aim of this assignment was to teach classes and interaction with each other, not to teach string concatenation

    Chris

  9. #9
    Junior Member
    Join Date
    Jan 2010
    Location
    North Wales
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: HELP!!! Entry Class to represent entries in a telephone directory

    How would you break the form of plagurism? Im not asking you to do it lol just asking for a bit of help which is allowed Anyway I've managed to do it now with the help from Java Enterprise LOL! What year you in? And what you studying?

    Yeah I am Web Developer and Web Designer it is my main field of interest! I was suppose to be at Manchester studying Web Development but due to family problems had to transfer to Bangor for a bit

  10. #10
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: HELP!!! Entry Class to represent entries in a telephone directory

    Well im glad you have got it sorted.

    I'm a first year Computer Scientist, how about you?

  11. #11
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: HELP!!! Entry Class to represent entries in a telephone directory

    While we are on the subject of phone numbers, there is only one way that these should be stored and that is as a string with numbers only. No spaces, no dashes no nothing, just numbers, maybe even with country code at the beginning.

    // Json

Similar Threads

  1. where can i find the tmp/foo directory?
    By Idy in forum Java IDEs
    Replies: 11
    Last Post: January 19th, 2010, 11:21 AM
  2. How to represent a chain of moves?
    By maikeru in forum Collections and Generics
    Replies: 0
    Last Post: December 31st, 2009, 01:24 AM
  3. how to add a new entry in a current array
    By chronoz13 in forum Java Theory & Questions
    Replies: 1
    Last Post: December 28th, 2009, 06:39 PM
  4. Class directory
    By Kit in forum Java Theory & Questions
    Replies: 7
    Last Post: October 11th, 2009, 10:07 AM
  5. How to detect audio input from a telephone call?
    By ces_31 in forum Java Theory & Questions
    Replies: 0
    Last Post: August 12th, 2009, 12:45 AM