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

Thread: Code help

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Code help

    Trying to write a code that store email addresses and phone numbers. I know I am missing a lot but have no idea how to do it.

    <package AddressBookEntryApp;
     
    	import java.io.BufferedWriter;
        import java.io.FileWriter;
        import java.io.IOException;
        import java.util.Scanner;
     
        import javax.swing.JOptionPane;
     
    	public class AddressBookEntry 
    	{
     
    		/**
    		 * @param args
    		 */
     
    		// save an AddressBookEntry object to the file
    		public static void saveEntry(AddressBookEntry entry) 
    		{
     
    		}	
     
    		public static void main(String[] args)
     
    		{
     
    			int listEntries;		// to look up name
    			int addEntry;			// add new name and information into system
    			int exit;				// to exit the system
     
    		    //Print out the welcome screen
    			System.out.println("Welcome to the Address Book application");
    			System.out.println();
     
    			//Asks user to input new email address & phone number.
    			String email = JOptionPane.showInputDialog("Enter list entries:");
    			String PW = JOptionPane.showInputDialog("Enter add entry:");
     
    			try
    			{
     
    			String info = null;
    			BufferedWriter out = new BufferedWriter(new FileWriter(info));
     
    			out.write("------------------");
    			out.newLine();
    			out.write("E-mail: " + email);
    			out.newLine();
    			out.write("Phone number: " + PN);
    			out.newLine();
    			out.write("------------------");
    			out.close();
     
    			}catch(IOException e) {}
    			System.exit(0);
     
     
    			}
    	}


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Code help

    Can you explain what your problem is?

    One thing you should put in your code is a call to the printStackTrace() method in the catch block so that you will get an error message if there is an exception.

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Code help

    What I am trying to do is to store email address and phone numbers in this program. the console should come up with 1 - list entry, 2- add entry and 3 exit, then i would click the number of what i want to do. But can't get passed the welcome part.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Code help

    What values are returned by the calls to the showInputDialog() methods when you call them?
    Use println statements to print out the Strings' values to see what the user has entered.

    The code you posted does not compile without errors. You need to fix the compiler errors before you can execute the code.
    Last edited by Norm; March 9th, 2012 at 09:34 AM.

Similar Threads

  1. code to refresh and check the code of a webpage..
    By vaggelis in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 7th, 2012, 07:43 AM
  2. Help merging program code with GUI code
    By Wilha in forum AWT / Java Swing
    Replies: 2
    Last Post: January 25th, 2012, 07:03 PM
  3. problem in my code java code graph editeur
    By kisokiso in forum Java Theory & Questions
    Replies: 5
    Last Post: January 6th, 2012, 08:36 AM
  4. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 09:30 PM
  5. 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