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: Where did I mess up?

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    4
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Where did I mess up?

    // CIS 226 Ch 2 Welcome to CIS 226
    	// Assign2 - Create a program which prompt user to enter first and last name and a welcome message is displayed. 
    	// Riter Heng - 2/16/2012
     
    // for Extra Credit
     
     
    import javax.swing.JOptionPane;
     
    public class Assign2 
    {
     
     
    	public static void main(String[] args) 
    	{
    		//System.out.println("Welcome to CIS 226!");
    		//System.out.println("..");
    		//System.out.println(("..\n..");
    		//System.out.printf("%s\n%s\n", "..", "..");
     
     
    		String firstName = JOptionPane.showInputDialog("Please enter your first name:");
    		//if (firstName != null) {}
    		//else {System.exit(0);}
     
    		String lastName = JOptionPane.showInputDialog("Please enter your last name:");
    		if((firstName != null) || (lastName != null))
     
    		JOptionPane.showMessageDialog(null, "Hello, " + firstName +"  " + lastName + ", " +
    									"\n Welcome to CIS 226", "Message" , 0);
    		else {JOptionPane.showMessageDialog(null, "Sorry, you have enter your name to enroll into CIS 226.", "Error", JOptionPane.ERROR_MESSAGE);}
     
     
    	   } // end method main
    }// end class Assign2

    Okay so I was working with a classmate and he sorta left in the middle to go somewhere and I was left trying to figure out his coding. The program is suppose to give an error when you click cancel instead of not entering a first or last name. But it doesn't give that error and just skips on over and ends up at the "hello firstName Last Name, Welcome to CIS 226." Also when I ran it on the "hello..." I get a red cross as the icon but I need a "i", how do I fix that?


  2. #2
    Junior Member
    Join Date
    Feb 2012
    Location
    Bedroom
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Where did I mess up?

    The problem seems to be on the following lines:

    ...edited by moderator

    So whenever the user click the cancel button the program will show the error message and then it exit.

    My first post here. I hope it answers your question.
    Last edited by copeg; February 17th, 2012 at 10:12 AM.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Where did I mess up?

    @Sevv, please read the forum rules as well as the following:
    http://www.javaprogrammingforums.com...n-feeding.html

  4. #4
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: Where did I mess up?

    I had problems dealing with this exception: try/catch Statement | Example Depot
    Go here and read up on it.

    tl/dr use a try/catch statement

Similar Threads

  1. Object-oriented mess
    By mjpam in forum Object Oriented Programming
    Replies: 3
    Last Post: May 7th, 2011, 11:27 AM