Getting null and 0 outputting to screen or file.

Hi everyone,
I am trying to make a phone book program in Java. However the main functions of the phone book (adding and displaying contacts) isn't really working, it is outputting null or 0.
Here is a class to create an object for family members:
import java.util.StringTokenizer;
public class phoneFamily extends phoneNumbers
     protected int home;
     public phoneFamily(String name, String address, int mobile, int business, int home)
          super(name, address, mobile, business);
          this.home = home;
     public phoneFamily(StringTokenizer P)
          super(P);
          while (P.hasMoreTokens()){home = Integer.parseInt(P.nextToken());}
     public void setHome(int home)
          this.home = home;
     public int getHome()
          return home;
     public String toString()
          return "Name: " + name + "\nAddress: " + address + "\nMobile: " + mobile +
               "\nBusiness: " + business + "\nHome: " + home;
     public String CSV()
          return name + "," + address + "," + mobile + "," + business + "," + home;
}Now I'm assuming that the problem I am having, where null or 0 is written to the file and screen is caused by the methods that reads a contact, writes them to the file, prints them to the screen. Here are those bits of codes.
Reads Contact:
private phoneNumbers ReadContact()
          int x = 0;
          String contact;
          StringTokenizer S;
          while (x < 1 || x > 3)
               System.out.print("Which type of contact would you like?");
               System.out.print("\n1)Family\n2)Workers\n3)Friends");
               x = keyboard.nextInt();
          contact = ReadString("contact name") + "," +
                     ReadString("address") + "," +
                     ReadString("mobile") + "," +
                     ReadString("business") + ",";
          if (x==1)
               contact+=ReadString("home");
          else if (x==2)
               contact+=ReadString("email") + "," + ReadString("job title") + "," + ReadString("department");
          else
               contact+=ReadString("email") + "," + ReadString("home");
          S = new StringTokenizer(contact,",");
          if (x==1)
               return new phoneFamily(S);
          else if (x==2)
               return new phoneWorkers(S);
          else
               return new phoneFriends(S);
Writes to File
public void Save() throws IOException
          PrintWriter phoneFile = new PrintWriter(new FileOutputStream(PH_FILE));
          for (int i=0;i<NumOfContacts;i++)
               String phoneX = phone.CSV();
               phoneFile.println(phoneX);
          phoneFile.close();
          System.out.println("Contacts have been saved successfully.");
Prints on Screen
public void PrintFamily()
          System.out.println("Contacts Stored as FAMILY:");
          System.out.println("");
          //#=7, Name=24, Address=28, Email=24, Mobile=12, Business=12,
          System.out.println(SpaceGen("#",7) + SpaceGen("Name",24) + SpaceGen("Address",28) +
               SpaceGen("Mobile",12) + SpaceGen("Business",12) + SpaceGen("Home",12));
          //System.out.println(RepChar('=',100));
          for (int i=0;i<NumOfContacts;i++)
               if (phone[i] instanceof phoneFamily)
                    System.out.print(SpaceGen((new Integer(i+1)).toString(),7));
                    System.out.print(SpaceGen(phone.getName(),24));
                    System.out.print(SpaceGen(phone[i].getAddress(),28));
                    System.out.print(SpaceGen(new Integer(((phoneFamily)phone[i]).getMobile()).toString(),12));
                    System.out.print(SpaceGen(new Integer(((phoneFamily)phone[i]).getBusiness()).toString(),12));
                    System.out.print(SpaceGen(new Integer(((phoneFamily)phone[i]).getHome()).toString(),12));
          //System.out.println(RepChar('=',100));
For some reason the last thing you enter when adding a contact (example above, home number), gets displayed first (when it should be name) and the rest are null or 0. The file looks something like this (in CSV)
111222333,null,0,0,0
The "111222333" is supposed to be the name but like I said last value entered is being put first.
I've gone over my code several times, with no luck :-(.

I made a silly mistake in the bit where the details are read. After fixing that everything is running well :-).
My mistake:
I had something like:
while(P.hasMoreTokens()){this.data = P.nextToken();}
while(P.hasMoreTokens()){this.data2 = P.nextToken();}
and so on...Obviously had to use "if"s and not "while"s to read the data...
Thanks for offering a helping hand :-) though!

Similar Messages

  • HT201210 i updated my iphone 3gs to iphone 6 . while installing the software it gets error and closed. then i restored my previous version. when i turned on the phone it gets usb and itunes symbol on screen. when i run itunes error is coming like server c

    i updated my iphone 3gs to iphone 6 . while installing the software it gets error and closed. then i restored my previous version. when i turned on the phone it gets usb and itunes symbol on screen. when i run itunes error is coming like server contact problem. what can i do to start my phone????  plz help me

    I will need a little bit of information about your phone. What kind of error are you getting?

  • I have a macbook 2011 and its booting to the apple with a loading bar. it gets halfway and changes to a screen with the apple and a spinning circle. It spins untill it dies. will not boot to safe mode. Do not have orriginal osx disk either.... HELP :(

    i have a macbook 2011 and its booting to the apple with a loading bar. it gets halfway and changes to a screen with the apple and a spinning circle. It spins untill it dies. will not boot to safe mode. Do not have orriginal osx disk either.... HELP

    It happened after an update

  • Execute command and save output in a HTML File

    Hello Guys,
    I have a requirement and for that i have to do following. a) read a file in an array and then execute a command for each value in that array. after that i want to store the output of command and value of array in another array.
    i am doing something like below.
    set objtextfile = objfso.opentextfile _
    ("c:\temp\aaaa.txt", forreading)
    j=0
    Do until objtextfile.atendofstream
    redim preserve arr123(j)
    arr123(j) = objtextfile.readline
    j = j+1
    Loop
    for each server in arr123
    chk_status = "command" &" "& server
    set objexecobject = objshell.exec(chk_status)
    'Here i am not sure how to proceed further to achieve what i described above.
    Next
    Can someone help me with this?
    -KAKA-

    Thank you for your response.
    So here is what i want to do.
    Query a database using odbc from my management server (odbc is configured and connection is tested) and based on the query it will result out few list of servers. then from the same management server i want to execute a command against all the resulted server
    (management server has a binary which can execute remote action). this remote action will get output back.
    then i would like to store the name of server and resulte output in a html file which should look like below.
    which i will later host on apache.
    YOu do not need to move things in and out of arrays and files.
    >>>> You are right but as i stated, i am not a core programmer and due to nature of my job i have to work on perl, shell and VB Script, apart from my actual technology so it becomes difficult to write it with perfection.
    I hope you understand.
    -KAKA-
    -KAKA-

  • How to get nodes and its attributes of an XML file usiong DOM parsing?

    how to get nodes and its attributes of an XML file usiong DOM parsing?
    i am new to XML parsing.......
    Thanking you........

    import org.w3c.dom.Document;
    import org.w3c.dom.*;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;      ...
    //Setup the document
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
         DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
         Document doc = docBuilder.parse (new File("MY_XML_FILE.xml"));
    //get elemets by name
         String elementValue = doc.getElementsByTagName("MY_ELEMENT").item(0).getTextContent();
    //This method can return multiple nodes, in this instance I get item(0) , first nodeRead the api for other methods of getting data.

  • Ctrl+S and file save just get ignored and I have to close the file to save docs

    I am using DW CS5.5.
    Ctrl+S and file>save just get ignored and I have to close the file to save docs.
    Any ideas? Thanks

    "If this configuration folder is the one in the Program Files hierarchy, you may have shot yourself in the foot.  Never mess with those."
    I had a neighbor one time who was annoyed that "that darn bolt on the bottom of my engine" kept scraping on the curb when he'd pull in or out of his driveway, so he ground it down till it was flat with the oil pan. It wasn't till about a year later when he took the car in to have the oil changed that he realized the error of his ways. Cost him $500 to have the pan pulled and replaced.
    If you don't know what it does, find out first or leave it alone.

  • Using Yosemite - cannot project screen onto TV.  Get bits and pieces or black screen.  Have been using same setup for years.

    Using Yosemite - cannot project PC screen onto TV.  Can get a black screen or bits and pieces of a screen ( not always the one displayed on PC).  Have been using same setup for years.
    Thanks for any help

    Hi, edward.  
    Thank you for visiting Apple Support Communities.  
    I understand that you are having a display issue with your MacBook Pro on your TV.  I would need a little more information regarding how you are connecting your device and what content is being displayed to provide a better answer.  However, here is the best troubleshooting resource to go through when experiencing these symptoms.  
    Apple computers: Troubleshooting issues with video on internal or external displays
    http://support.apple.com/kb/HT201177
    Cheers, 
    Jason H.

  • Get input and display output on same screen for report

    Hi frnds,
    two params
    that is mat.no,desc.
    enter the mat.no and also display the description of that mat.no in same input screen for the report.
    How can i archieve .
    Thanks in advance.

    Hi,
    It is not possible in Dialog Programming too. But there is an alternative. You can make the material number field as drop down. Assign a function code to that. Now in PAI you can code accordingly to display the description.
    In TOP.
    TABLES: mara, makt.
    DATA  gv_maktx TYPE makt-maktx.
    In PAI.
    CASE sy-ucomm.
    WHEN 'F_MATNO'        "function code assigned to the material number drop down field
         SELECT SINGLE maktx
          FROM makt
          INTO gv_maktx
          WHERE matnr = mara-matnr. " mara-matnr is the dictionary reference to the material number drop down field in the screen.
          makt-maktx = gv_maktx.    " makt-maktx is the dictionary reference to the material description field in the screen.
    ENDCASE.
    Thanks,
    Sri.

  • Error during installation OS 10.8.2 getting restart  and thin black break screen

    error during installation OS 10.8.2 getting restart after apple logo several times and thin black&white crashed screen

    I had this problem too.
    Go to http://support.apple.com/kb/DL1580
    Download the update manually and install. Worked on my MBP15 retina.
    Regards
    Chris

  • Cannot get Month and Year display off screen

    In Iphoto 6 I have photos that I imported. I cannot get the middle dark oval in the center of the screen to stop displaying on the photos.
    It makes it very difficult to edit the photos when I cannot see the center of the photo.
    How do I stop the display of the month and date

    In iPhoto Preferences, Appearance, uncheck "Show scrolling information."

  • Getting links and its names from a html file

    Hi everyone
    My problem about the a getting links with name from a html file. For example
    &#304;n a web page in this site ?SUN? when use click SUN the browser open http://java.sun.com
    &#304; want both of them, so the links and name. I can succeeded the get link but i don t know how to get the link name.
    For example :
    <B>setRightComponent(Component)</B>
    &#304;n this code segment i want to get B tag. But how i don t know. To get A tag i used this code
    List result = new ArrayList();
    try {
    // Create a reader on the HTML content
    URL url = new URI(uriStr).toURL();
    URLConnection conn = url.openConnection();
    Reader rd = new InputStreamReader(conn.getInputStream());
    // Parse the HTML
    EditorKit kit = new HTMLEditorKit();
    HTMLDocument doc = (HTMLDocument)kit.createDefaultDocument();
    kit.read(rd, doc, 0);
    // Find all the A elements in the HTML document
    HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
    while (it.isValid()) {
    SimpleAttributeSet s = (SimpleAttributeSet)it.getAttributes();
    String link = (String)s.getAttribute(HTML.Attribute.HREF);
    if (link != null) {
    result.add(link);
    it.next();
    &#304; can use B tag but i don t know hot to get its value because it has no prefix such as HREF....
    i am sorry if i use a bad explanation style or incorrect word.

    import java.io.*;
    import java.net.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    class GetLinks
        public static void main(String[] args)
            throws Exception
            // Create a reader on the HTML content
            Reader reader = getReader( args[0] );
            // Parse the HTML
            EditorKit kit = new HTMLEditorKit();
            HTMLDocument doc = (HTMLDocument)kit.createDefaultDocument();
            doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
            kit.read(reader, doc, 0);
            // Find all the A elements in the HTML document
            HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
            while (it.isValid())
                SimpleAttributeSet s = (SimpleAttributeSet)it.getAttributes();
                String href = (String)s.getAttribute(HTML.Attribute.HREF);
                int start = it.getStartOffset();
                int end = it.getEndOffset();
                String text = doc.getText(start, end - start);
                System.out.println( href + " : " + text );
                it.next();
        // If 'uri' begins with "http:" treat as a URL,
        // otherwise, treat as a local file.
        static Reader getReader(String uri)
            throws IOException
            // Retrieve from Internet.
            if (uri.startsWith("http:"))
                URLConnection conn = new URL(uri).openConnection();
                return new InputStreamReader(conn.getInputStream());
            // Retrieve from file.
            else
                return new FileReader(uri);
    }

  • Strange behavior when getting data and storing it into a tdms file

    Hi
    I am getting data from a VISA device(10bytes every 20ms) in a string buffer and then using indexing array get each element which is 2 bytes , filtering the data in real time using a butterworth filter and then storing the data to a TDMS.
    The problem is that the data goes haywire after a brief the the different elemetns just switch. So for example x becomes resistance, GSR becomes  etc
    I have uploaded the VI and the TDMS file converted to excel format

    You really should be writing to the TDMS file while you acquire the data.  By using the Autoindexing Tunnels to build the arrays, you are causing A LOT of memory allocations, which causes things to really slow down.  I would venture to say that you are missing data, causing what looks like a shift in the data.  But you would need to be looking at the error coming out of the VISA Read to know for sure.
    So look into the Producer/Consumer.  The idea is to use a parallel loop to log the data while your current loop reads and processes the data.  The data is sent to the consumer loop via a queue.

  • How do I get itunes and iphoto to have the same files on multiple users?

    Every time I upload a disc or photos, they show up on my user profile, but not my wife's. It seems like I am wasting a ton of hard drive space reloading the same things between each user. I tried the "shared" folder, but i am not sure that worked.
    Thanks for the help...

    I don't think that Thomas's solution will work on 10.5.
    There are two ways to share, depending on what you mean by 'share'.
    If you want the other user to be able to see the pics, but not add to, change or alter your library, then enable Sharing in your iPhoto (Preferences -> Sharing), leave iPhoto running and use Fast User Switching to open the other account. In that account, enable 'Look For Shared Libraries'. Your Library will appear in the other source pane.
    Remember iPhoto must be running in both accounts for this to work.
    If you want the other user to have the same access to the library as you: to be able to add, edit, organise, keyword etc. then:
    Quit iPhoto in both accounts
    Move the iPhoto Library Folder to an external HD set to ignore permissions. You could also use a dmg.
    In each account in turn: Hold down the option (or alt) key and launch iPhoto. From the resulting dialogue, select 'Choose Library' and navigate to the new library location. From that point on, this will be the default library location. Both accounts will have full access to the library, in fact, both accounts will 'own' it.
    However, there is a catch with this system and it is a significant one. iPhoto is not a multi-user app., it does not have the code to negotiate two users simultaneously writing to the database, and trying will cause db corruption. So only one user at a time, and back up, back up back up.
    Regards
    TD

  • How do I get LR3 and CS5 read Nikon P7700 raw files?

    Just bought a Nikon P7700 so I can use the Raw feature.  CS5 and LR3 do not read the P7700 Raw Files....does Adobe have an update and/or plugin for this?

    It depends.....if your normal route into PS is through Lightroom and the "Edit in..." process, then no you won't need to update PS as well as Lightroom will handle the Raw conversion. But if you have a need to directly open raw files into Photoshop's ACR plug-in, then yes you would need to upgrade PS as well.

  • By entering month and year in selection screen

    Hi Friends,
                   My requirement is , when i enter month and year in selection screen and again i press enter now it show me the begin and end date of that month  in selection screen.
    Thanks & Regards,
    Himanshu

    u can use this type of code...
    AT SELECTION-SCREEN.
      DATA it_dynfield TYPE STANDARD TABLE OF dynpread WITH HEADER LINE.
      CALL FUNCTION 'DYNP_VALUES_READ'
        EXPORTING
          dyname               = sy-repid
          dynumb               = sy-dynnr
          request              = 'A'
          translate_to_upper   = 'X'
        TABLES
          dynpfields           = it_dynfield
        EXCEPTIONS
          invalid_abapworkarea = 1
          invalid_dynprofield  = 2
          invalid_dynproname   = 3
          invalid_dynpronummer = 4
          invalid_request      = 5
          no_fielddescription  = 6
          invalid_parameter    = 7
          undefind_error       = 8
          double_conversion    = 9
          stepl_not_found      = 10
          OTHERS               = 11.
      READ TABLE it_dynfield WITH KEY fieldname = 'month'.
      IF it_dynfield-fieldvalue IS NOT INITIAL.
        month = it_dynfield-fieldvalue.
      ENDIF.
      READ TABLE it_dynfield WITH KEY fieldname = 'year'.
      IF it_dynfield-fieldvalue IS NOT INITIAL.
        year = it_dynfield-fieldvalue.
      ENDIF.
    use FM HR_JP_MONTH_BEGIN_END_DATE..
    get startdate and enddate
    AT SELECTION-SCREEN OUTPUT.
    startdate = <start date from FM>.
    end date = <end date from FM>.

Maybe you are looking for