// 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?