public void startConversation() { String fullName = JOptionPane.showInputDialog("Enter full name:"); String lastName = nameService.extractLastName(fullName); String msg = "Your last name is: " + lastName; JOptionPane.showMessageDialog(null, msg); }
public void startConversation() { try { String fullName = JOptionPane.showInputDialog("Enter full name:"); String lastName = ""; lastName = nameService.extractLastName(fullName); String msg = "Your last name is: " + lastName; JOptionPane.showMessageDialog(null, msg); } catch (NullPointerException npe) { JOptionPane.showMessageDialog(null, npe); } }
/** Gets the user's full name and outputs the last name */ public void startConversation() { String fullName = JOptionPane.showInputDialog("Enter full name:"); String lastName = ""; try { lastName = nameService.extractLastName(fullName); } catch (NullPointerException npe) { System.out.println(npe.getMessage()); } catch (EmptyStringException ese) { System.out.println(ese.getMSG()); } catch (IllegalNameException ine) { System.out.println(ine.getMSG()); } String msg = "Your last name is: " + lastName; JOptionPane.showMessageDialog(null, msg); }