Results 1 to 9 of 9
  1. #1
    ZinoXxX is offline Member
    Join Date
    Mar 2012
    Posts
    5
    Rep Power
    0

    Default Simple First Java program: Basic Contact register

    Hey all,
    I just started studying Java programming, and one of our assignments is to create a "phonebook" or contact register, I have done some thinking when it comes to this very basic program, but Im stuck at the register class, Ill provide details and more information below.

    You dont have to provide me with the answer necessarily but the tools to get there or the boost to get started :).

    Ok, so... I figure I am going to need 2 classes for this program to work somewhat functional, anyway, I was thinking one class named Person.java and one named Register.java.

    Attributes i thought of when thinking of the Person.java is Names and phone numbers, nothing fancy but that will do. (Unless I am missing some related data required to store these two types of information)
    The Register I have absolutely no idea what kind of Attributes is required, there I might need some coaching.

    Functions needed; getName, getNumber and showAll (I figure that getName and getNumber belongs to the Person.java, and showAll to the register, but I could be wrong... It is, afterall, my first program ;)).

    Operations needed; changeNumber, addPerson and removePerson (Here honestly I dont really know what goes where :/).

    And I also figured that it must be easiest to use an indexed variable for the register itself (?).

    And also I have some trouble getting started with specification of each class etc. and getting started generally too, I might add.

    Appreciate all support and guidance on this one, first time I post a thread on this forum as well but I hope you can help :).

    Cheers,
    ZinoXxX

  2. #2
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    3

    Default Re: Simple First Java program: Basic Contact register

    Are you going to keep the information in some sort of Collection ( ArrayList, HastMap.. ) or some file on your hard drive ?

  3. #3
    skynet357 is offline Member
    Join Date
    Mar 2012
    Location
    Hyderabad, India
    Posts
    8
    Rep Power
    0

    Default Re: Simple First Java program: Basic Contact register

    The Register I have absolutely no idea what kind of Attributes is required, there I might need some coaching.
    Whenever you are trying to figure out the attribute of a class try to relate it to the real world object. In this case relate you register class to a real register. what does it contain? serial number, name etc. Not disclosing much details so that you try it personally and get a experience.


    Operations needed; changeNumber, addPerson and removePerson (Here honestly I dont really know what goes where :/).
    Same thought process also applies to the methods that you define for your class. Just list out the functions that you perform in a register. If you have already listed them(as in this case. ChangeNumber,addPerson and removePerson) just think how to achieve what the name says. I mean the ChangeNumber method should be able to change the contact number of the corresponding person and so on.

    Even i am not that matured in java. Just Six months into this
    Although this is a simple program I feel you can start with even simpler program to get acquainted with getters and setters, constructors etc.. I mean the absolute basics.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default Re: Simple First Java program: Basic Contact register

    The Register obviously is some sort of 'bag' of Person objects. Does it allow duplicate Persons in its bag? Does it allow Person objects that aren't registered? If not, a Register should create a Person and put it in its bag (possibly after some checking). A Person should be able to display itself (name and phone number?) A Register should be able to display all Person objects in its bag. Maybe you want additional functionality for the Register (remove a Person? remove them all? Sort them by name or phone number? find a Person's name given its phone number?) Think about all these aspects and decide what (the Register or a Person) should implement the functionality.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    ZinoXxX is offline Member
    Join Date
    Mar 2012
    Posts
    5
    Rep Power
    0

    Default Re: Simple First Java program: Basic Contact register

    I was thinking very basic really (I think), the register should contain all the persons that are registered, and I would like a function to show all the persons contained within the list at a specific moment, as well as the possibility to enter "search-term" or just a name, and get respective number, or enter a number and get respective name.

    I do only want to have the possibility of erasing a person, adding a person or editing a person, not massremoval or massadding or such of any sort I think...

    I feel a little confused about the whole combination with the use of 2 classes, also I have doubts when it comes to where the main method should be put, or if these 2 classes is external and separated from the main-method?

    Name and phone numbers are the two only attributes (?) that persons should have, not any more fancy than that really.

    Problem I got that weighs the most is the start though, I have been programming applets with java earlier, and found that very easy, although that was not quite so advanced either Im afraid, but I knew what I was doing and how I could go about to do it, even though it took a little while to figure out the red thread to be following to reach the finish line.

    I feel like this is so much different than applets though, not used to having more than 1 class containing different parts of the puzzle, normally Im programming languages like HTML, XHTML, CSS and it just seems so much more different and more difficult to handle Java compared to those other three..

  6. #6
    ZinoXxX is offline Member
    Join Date
    Mar 2012
    Posts
    5
    Rep Power
    0

    Default Re: Simple First Java program: Basic Contact register

    That is the problem, I dont really know if I need the Register class or if it may be unecessary efforts?

    And if so, I got to somehow get a hold on how to proceed from here to the finish line, and at this moment, Im as clueless as a common rock...

  7. #7
    ZinoXxX is offline Member
    Join Date
    Mar 2012
    Posts
    5
    Rep Power
    0

    Default Re: Simple First Java program: Basic Contact register

    I hadnt really considered the storage ;o

    I just assumed that they would be stored within the program, didnt really think the whole offline-storage solution through I believe :/
    But it would be nice if there were a way to saving the information, in text-file or whatever (not sure how these things work in Java, as you might have noticed) :)

  8. #8
    ZinoXxX is offline Member
    Join Date
    Mar 2012
    Posts
    5
    Rep Power
    0

    Default Re: Simple First Java program: Basic Contact register

    It feels like my head cant separate this from that when Im programming software in Java, and I have now tried to make source code for the program I intended to create, however it is very likely to be faulsy at many places and also it might very well be totally crazy, since I dont really know what Im doing whilst im coding, but the principle thought should be there at least (I think), and also the program/software has been reduced to only a person instead of both person and register to make it as simple as possible for my brain to grasp, and I still need some help though Im afraid...

    Im gonna paste the code anyhow and see if you can sort my brains out a little bit ;p.


    import java.util.Scanner;

    public class Person {
    private String Name1 = "Kalle", Name2 = "Karl", Name, nom;
    private int Nbr1 = 7070, Nbr2 = 5050, nbr, numero;


    public Person(String name, int phone){
    this.Name = name;
    this.nbr = phone;
    }
    public String getName(){
    /*Description of what this function is meant to do if perfectly and correctly created: Get a text presented to user, telling him/her or w/e to enter the number of the person they are looking for
    * and then the nbr should be checked within an indexed variable, when it is found, the name that belongs to the number should be returned.*/

    Scanner scan = new Scanner(System.in);
    int entrNbr = scan.nextInt();
    if (entrNbr == Nbr1){
    nom = Name1;
    }
    else if (entrNbr == Nbr2){
    nom = Name2;
    }
    System.out.println("Number you have entered belongs to " + nom);
    return nom;
    }
    public int getNumber(){
    /*Description: somehow get the user to enter the name of the person they or w/e is looking for, then the name goes crossreferenced with the "register" or something to
    * get the corresponding number to this person.*/

    Scanner scan = new Scanner(System.in);
    String inptTxt = scan.nextLine();
    if (inptTxt == Name1){
    numero = Nbr1;
    }
    else if (inptTxt == Name2){
    numero = Nbr2;
    }
    System.out.println("Name you have entered got following number: " + numero);
    return numero;

    }
    public void changeNumber(){
    /*Description: Allow user to enter the name of the person they would like to switch number on, and then erase old number in a register or something like that
    * and apply the newly updated number.*/

    Scanner scan = new Scanner(System.in);
    System.out.println("Enter the name of the person whos number you wish to change:");
    String Person = scan.nextLine();
    System.out.println("Enter the number you wish to switch the old number into:");
    int NyNumbr = scan.nextInt();
    if (Person == Name1){
    Nbr1 = NyNumbr;
    }
    else if (Person == Name2){
    Nbr2 = NyNumbr;
    }

    }
    public void changeName(){
    /*Description: Allow the user to enter the number of the person they would like to swtich Name on, and then erase the old name and enter the updated one correspondant
    * to the number linked to that persons name.*/

    Scanner scan = new Scanner(System.in);
    System.out.println("Enter the number belonging to the person's name you wish to change:");
    int Number = scan.nextInt();
    System.out.println("Enter the name you wish to change the old one into:");
    String NyName = scan.nextLine();
    if (Number == Nbr1){
    Name1 = NyName;
    }
    else if (Number == Nbr2){
    Name2 = NyName;
    }
    }
    public static void main(String[] args) {

    }


    }

    Please provide me with pointers of what could be improved, where I have taken the wrong turn, and also how to improve and figure out how to continue..

    Thanks in advance hope that you can help :).
    P.S.
    I especially got problems creating objects and then basing the functions and methods on top of created objects as well as storing them within variable or register of some sort.
    And also, this is not test-run, I bet there is tons of errors that didnt show up in editor, but that are there since I dont really know what I have created :/.
    D.S.

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default Re: Simple First Java program: Basic Contact register

    You're trying to do everthing at once in one terrible class; a Person should have one constructor that takes a name and a number; it should initialize a Person object given those attributes. A Person object should be able to supply a String representation of itself (in its toString() method) and (optinally) it should be able to compare itself against (another) Person object; if you want to do it right, it should be able to compare itself for equality as wel as a relational comparison (hint: read about the equals( ... ) method, the hashCode() method and the Comparable<T> interface. Reading names and numbers should be done outside the Person class (you don't want to clutter up the code in that class).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Help with login and register program?
    By OllyHal in forum New To Java
    Replies: 3
    Last Post: 02-08-2012, 05:57 PM
  2. need help to figure out basic java program
    By shane123 in forum New To Java
    Replies: 21
    Last Post: 12-02-2011, 04:12 AM
  3. Problem understanding basic Simple Enumerators
    By eLancaster in forum New To Java
    Replies: 31
    Last Post: 06-23-2011, 06:38 PM
  4. Simple java program, need help
    By cliffh in forum New To Java
    Replies: 1
    Last Post: 10-21-2010, 03:32 AM
  5. To access hotmail contact list using java
    By bharat_kasodariya in forum Advanced Java
    Replies: 1
    Last Post: 02-26-2009, 02:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •