Note for C SC 335 at UA
Popular in Course
Popular in Department
This 3 page Class Notes was uploaded by an elite notetaker on Friday February 6, 2015. The Class Notes belongs to a course at University of Arizona taught by a professor in Fall. Since its upload, it has received 13 views.
Reviews for Note for C SC 335 at UA
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 02/06/15
Pattern Exercise for the OO Factory Design Pattern Based on Desrgn Patterns Jaya Compamon James w Cooper http www pattemdepot eomputxJayapatterns htm You are readmg m the customer s names to estabhsh the last names and the rstname to estabhsh who rs ordenng orto rdentrfy the eorreet stnngs so anew eustomer could be addedthe database the data base has rstname and1astname elds However you want your eustomers to be able to enter therr name m ether of these two forms 1 FrrstName LastName 2 LastNameFrrstName You don t know how the eustomerwru enterthe name Desrgn the system to aeeept rnput for erther rst name followed by last name or for last name followed by a eomma followed by a rst name um 44m emername DueJane Emername JuhnDue nrsmame Jane nrsmame lnhn LastName Dne Lasmame nne mpaxr jeyexm mpaxr jeyem mpaxr javaavir Publn class uenerrene exeends meme lt Publn seeme vmd malnlscnngU area lt new quotameFIBmeLseVsblElcxue gt levace JTeer leld namelnpucheld levace Hebe flxsdlamelaabel levace Hebe lasdlameLabel Publn quotameanmEH lt LhsserTlELquotIlame rrenequot t Lhsser5zEL2EIEI nu t thssemefaulctlase pexamanlJanmelXITiEIILELEISE t Eancalnex cancencPane e chlsqectancencPanEUF cancencPanesecLaYauclnew srndteyoueta 2 4 4n canenrPaneaddLnew JLabeHquot Encex nene quot n nameInpud leld e new JTechleldU cancencPaneaddlnamelnpucheld t canenrPaneaddLnew JLabeHquot nrse uenequottt flxsc amelaabel e new neheu39vaant cancencPaneaddlflxsdlamelaabel t canenrPaneaddLnew JLabeHquot Last uenequottt lasdlameLabel e new neheu39vaaut cancencPaneaddllasc amelaabe t quotamelnpudalscenex npuchscenex e new ueneInnuetnseenem nameInPud leld addAcclanLlscenEI Llnpuchscenex t 1 private class NamelnputListener implements ActionListener 2 l 3 public void actionPerformedActionEvent e 4 l 5 Send the text to the factory and get a Namer object back 6 Namer namer NameFactorygetNamernameInputFieldgetText 7 Compute the first and last names using the returned class 8 String firstName namergetFirst 9 String lastName namergetLast 10 firstNameLabelsetTextfirstName ll lastNameLabelsetTextlastName 12 13 l4 Class FirstFirst will look a lot like this class LastFirst class LastFirst that splits the name as quotfirst lastquot when it is constructed public class LastFirst extends Namer public LastFirstString s int i sindeXOfquotquoti find comma if i gt O left is last name last ssubstringO itrim right is first name first ssubstringi ltrim else last s put all in last name first if no comma C Sc 335 In Class Activity 20 minutes Form a team of 2 or 3 and choose the scribe the person writing the answer today as the person sitting furthest north Circle the name ofthe Scribe s section leader Jessica Mark Andreea Mike Print each of your names 1 Draw a UML Diagram with the following 0 class Namer to capture common attributes and behavior Since the instance variables rst and last are set assigned the proper Strings in the subclasses declare them with protected access 0 class First First that splits the name as quot rst space lastquot when it is constructed class LastFirst that splits the name as quotlast comma space rst quot when it is constructed class Name Factory with a static method getNamer that returns an instance of Last First or Fi rst Fir st depending on whether a comma is found in the String argument 2 Write class Namer that returns the correct instance to the client see line 6 above
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'