How do I create a new method?

My application has the following code in one class:
private void updateSexField() {
String chosen = textChoice.getSelectedItem(); String theSex = theData.lookupSex(chosen);
sexField.setText(theSex);
private void updateAgeField() {
String chosen = textChoice.getSelectedItem();
String theAge = theData.lookupAge(chosen);
ageField.setText(theAge);
and this code in the other class:
public String lookupSex(String text) {
for (int i = 0; i <= top; i++)
if (text.equals(person.getSurname()))
return person[i].getSex();
return ("error");
public String lookupAge(String text) {
for (int i = 0; i <= top; i++)
if (text.equals(person[i].getSurname()))
return person[i].getAge();
return ("error");
The idea is that the correct sex and age, corresponding to a particular person (with a particular 'Surname') are returned back (or 'got'). Thes items are then placed in a text field in my program. There is actually several things being 'got' (only two are listed here but the code is identical). The big question is - How can I adjust the program so that a single method (or two) can perform each of these functions without having to write out the code over and over for each thing I want 'got', if you know what I mean.
Any advice, based on this limited description, would be much appreciated.
Cheers,
DJPesto

class Person {
    private final Hashtable attributes = new Hashtable();
    Person(String age, String sex) {
        attributes.put(PersonAttributes.AGE, age);
        attributes.put(PersonAttributes.SEX, sex);
    public Object getAttribute(PersonAttributes key) {
        return attributes.get(key);
class PersonAttributes {
    // this class implements a typesafe enum pattern
    // that can be used as keys in a Hashtable
    private final String attribute;
    private PersonAttributes(String atribute) {
        this.attribute = attribute;
    public String toString( ) {
        return attribute.name;
    public boolean eqauls( ) {
        return attribute.equals();
    public int hashCode( ) {
        return attribute.hashCode();
    public static final PersonAttributes AGE =
        new PersonAttributes("AGEATTRIB");
    public static final PersonAttributes SEX =
        new PersonAttributes("SEXATTRIB");
}

Similar Messages

  • How Do I Create a New Template for iBooks Author?

    Apple's provided templates are way too narrow for some of the ideas I want to implement. I do not see any real method for creating a template from scratch. I stripped one of the available templates down to nothing and rebuilt some of the pages and then selected Save As Template... but iBooks Author keeps the original template as the content instead of allowing me to use my own created Chapter, Section, and Pages with the Add Pages.. Button.
    How to you create a new template from scratch? I think it is absurd if you can only create a new template from one of the 6 predefined templates.

    Be careful on unlocking and deleting stuff, cause this very easily can destroy the layout and your current arrangement
    About dimensions, If i am not mistaken, i read on another thread that this cannot be happen.

  • How do I create a new account and get stuff from the old account to the new account

    How do I create a new account and get stuff from the old account to the new account

    There are instructions on this page for creating a new account : Set up an Apple ID in iTunes
    Or if you don't want to give credit card details : Create an iTunes Store, App Store, or iBooks Store account without a credit card or other payment method
    But you won't be able to transfer purchases from your old account to it, all content that you download from the store will remain tied to the account that downloaded it.

  • How can i create a new instance on unix

    Hi,
    How can i create a new instance(instance only) on UNIX and how can i mount my database with this new instance.

    udayjampani wrote:
    Hi,
    How can i create a new instance(instance only) on UNIX and how can i mount my database with this new instance.1) Define Instance in your way!!?
    If you simply create a pfile and startup nomount with it, then -in theory- you have an instance running ( this method is used e.g. for restoring a rman backup )
    2) You can't. Database files are bound to a certain instance. What you can do is recreate an instance with e.g. a different name, using the scripts generated by a 'alter database backup controlfile to trace;' command
    Cheers
    FJFranken

  • How can I create a new folder in Word for Mac ?

    How can I create a new folder in Word for Mac?

    You don't do this in Word. You do it in the OS X Finder.
    All you need do in Word is open the file, then select Save As from Word's File menu. Change the destination to your new folder then click on the Save button.
    The Finder method is much faster if you have a number of files you want to move. Just remember that to open those moved files in Word, you will have to change the directory from which you will open those files.

  • Stateful Session Bean, After remove is called how do I create a new SFSB?

    The application when is deployed creates a new SFSB, after the remove method is called the SFSB does not exist anymore, also the same happens in a timeout. How do I create a new SFSB without restarting the server?
    I am using EJB 3.0
    I don't understand really how in a shopping cart examples through different uses the correct SFSB is called for each user, with EJB 3.0
    Also how should I store the SFSB, I always called it through JNDI lookup.
    Thanks,
    Zoe

    The application when is deployed creates a new SFSB,
    after the remove method is called the SFSB does not
    exist anymore, also the same happens in a timeout.
    How do I create a new SFSB without restarting the
    server?
    I am using EJB 3.0
    Just as you created the firwst one. Assuming that you have a handle to the home object stored somehwere from your first call, you use home.create(var1, var2) or else look up the home using jndi and then call create on the home object.
    I don't understand really how in a shopping cart
    examples through different uses the correct SFSB is
    called for each user, with EJB 3.0
    Through your remote object. Each user has got his own remote object and for SFSB, one and only one bean is tied to a remote object. It's the container's responsibility to relate the remote object and the bean.
    Also how should I store the SFSB, I always called it
    through JNDI lookup.Store? Use a handle and if the handle is lost or an attempt to retrieve the remote object using the handle fails, look at #1 above (lookup home, create on home etc)
    >
    Thanks,
    Zoe

  • TS2756 How can i create a new usb connection (service)  on my iMac for sharing internet from my iPhone5 ( i seem have to deleted it )

    How can i create a new usb connection (service)  on my iMac for sharing internet from my iPhone5 ( i seem have to deleted it )
    i know its not a problem whit my carrier o data plan or sharing preferences on the ipone because when i use it un my laptop it works perfectly through
    the usb and even works on the Imac through wifi and bluethood tethering but NOT through usb!!.
    the problem is that trying to make it work i deleted the "profile" usb iphone on the network prefereces panel. Now i only have 3 options: ethernet / wifi / bluetooth
    but not the usb iPhone i used to have.
    And when i try to add a new one i dont get a USB option.
    can some one help me please??
    this is how it looks (after the bluetooth PAN i used to have USB iPhone option)

    The question would be more appropriate in the Mac forums as it is not really related to the iPhone.

  • How do I create a new icloud email address for my apple id?

    Hi there
    How do I create a new icloud email address for my apple id? My original email address is associated with my previous employers.
    When I send email from my Macbook, it seems as if I still work there, which is a problem.
    I would like to use the email address that I created for my iPad.
    When I login with my appleid (for my macbook) I keep getting the old company one, not the new one.
    Is there any way of resolving this? I
    Thanks
    Kelvin

    Welcome to the Apple Community.
    Providing you aren't trying to change you Apple iCloud email address you can make changes at My Apple ID

  • How can I create a new ring tone for my iPhone 4?

    How can I create a new ring tone for my iPhone 4? I followed the Garage Band process and ended up with the ring tone I want as a AAC audio file. It got stored in my iTunes a a song rather than a ring tone. How do I make it a ring tone vs. a song? I tried dragging it t the Ring Tone category at the bottom of the ITunes list, but it won't alloow me to move it?

    There's also an easy to use Applescript over at Doug's Applescripts for iTunes. It automates the whole thing. All you do is set the start and stop time on a file in iTuens and run the script. It will do everything else.
    Make Ringable v1.1
    http://dougscripts.com/475

  • How to i create a new itunes account for my old iphone so i can transfer data to new iphone, since my daughters new iphone is now linked to my acc and she ends up with all my apps and contacts etc

    My daughter has previously had an ipod which was linked to my itunes iphone account.
    she now has a new iphone and has linked this to that account and now she receives all my contacts apps etc when she syncs her account.
    How do i create a new itunes account for my old iphone so that i can transfer data to my new iphone and keep the two seperate so that when she deletes all my contacts and apps and then syncs her phone again we can still be compatible.

    iOS 5 & iCloud Tips: Sharing an Apple ID With Your Family

  • I have an iPad and and iPhone. They share an iCloud and I want separate iCloud accounts. How do I create a new account without losing any information? I want to keep the original account on one device.

    I have an iPad and an iPhone that share an iCloud account. I didn't realize when I got my iPad last year that when I signed up the iCloud on the device that it would share and use 5g of iCloud between the both of them. How do I unsync them and have two separate iCloud accounts? I don't care about sharing between them. When my kids put games on my iPad, I don't want them going on my phone. How do I create a new iCloud without losing any info on the other device?

    Hi sugaliko,
    You may need to set up your BlueTooth connection to the keyboard again. Use the steps in this article for guidance -
    iOS: Third-party Bluetooth accessories
    http://support.apple.com/kb/HT1664
    Thanks for using Apple Support Communities.
    Best,
    Brett L

  • I have itunes on my computer but its my wifes account. how do i create a new account for me?

    i have itunes on my computer but its my wifes account. how do i create a new account?

    I have the same problem,,,any help please ? thnx

  • I am trying to install a Canon Pixma MG8220 which requires my Airport Extreme password. I do no know it. I then  went to default Airport settings and renamed my network, but Airport required my password. How do I create a new password?

    How do I create a new password for my Airport Extreme if I do not know the old password?

    If you have the Mac that you used to configure the AirPort Extreme originally, you may be able to retrieve the password from KeyChain Access.
    See this User Tip from forum expert Tesserax:
                     AirPort - Regain Access from Forgotten Passwords
    If still no luck, you can reset the passwords again. Pay very close attention to the information about a Soft Reset in this Apple support document:
    Resetting an AirPort Base Station or Time Capsule FAQ

  • How do I create a new frame using Flash CS5 on a Mac so I can add more pictures to my website?

    I have what I hope is a fairly straight forward question that I hope you can answer if you write code with a Mac or are at least familiar with the process on a Mac?  The person I have been working with to create my photography website uses a PC.  Here is the problem.  I am trying to use my Mac in order to create frames so that I can add 5 more images to a portfolio that presently has 15 images.  The code is in an index.fla file.  If I want to create a new frame in the index.fla, let's say LOAD CODE 381 and want to use the same text that is already present in LOAD CODE 380 but with a few edits, I have no trouble going to the Action-Movie Clip and finding LOAD CODE 380 in the left hand column.  The problem is, on a Mac, how do I create frame LOAD CODE 381 and then how do I copy and paste the text from LOAD CODE 380 into LOAD CODE 381?  It looks like on a PC one can open LOAD CODE 380 in the Action-Movie Clip, highlight the text then right click on the red rectangular box in the timeline.  By doing so (on a PC) one sees a drop down menu that gives the option to "copy key frame".  What is the equivalent of the "copy key frame" on a Mac?  I can see where on the Mac you can go to Edit >copy.  Is this the equivalent of "copy key frame" on a PC?  If so, once I "copy" the text how do I create the new LOAD CODE 381 so that I can paste the text into the new frame?
    I WOULD BE EXTREMELY GRATEFUL TO ANYONE WITH THE ANSWER TO THIS QUESTION!  THANK YOU!!!!!

    Sorry not to be more clear.  It is a name assigned to one of the 
    frames by the person who originally designed the website and is shown 
    in the list of about 150 action frames that were created in this 
    particular fla document.  This "list" comes up in the left hand column 
    of the Action-Frame box. When I click on Load Code 380 which is half 
    way down the column of frames, the following text comes up on the 
    large screen to the right of the column of 130 frames.
    IMAGE.gotoAndPlay("start");
    loadVariables("data/series01/15title.txt", "_root.IMAGE.TITLE");
    loadVariables("data/series01/15price.txt", "_root.IMAGE.PRICE");
    loadMovie("data/series01/about.swf", "_root.IMAGE.ABOUT");
    IMAGE.mc_pic.attachMovie("pic","pic",1,)
    IMAGE.mc_picTHUMB.attachMovie("pic","pic",1,)
    This text is what I am trying to transfer to copy then paste into a 
    new frame after which time I want to slightly edit the text.  I am not 
    a programer so I apologize if I am not using all of the correct 
    terminology.
    Thank you again,  Jon

  • How do I create a new apple store account when my phone tells me that I have exceeded the maximum limit on this phone

    How do I create a new apple store account when my phone tells me that I have exceeded the maximum limit on this phone

    http://support.apple.com/kb/HT4627

Maybe you are looking for

  • Unable to load the dll essapinu.dll (Integration Of essbase and OBI)

    Hi, I am facing an issue in generating the Hyperion-Essbase report in OBI presentation service. I have integrated essbase DB in OBI RPD and after that I dragged the catalogs of Essbase to BMM-->PL.Then made the consistency check and till this point i

  • Airport Utility instant crashes when i open it.

    Can this have happened because i deleted some files using daisy disk? Process:         AirPort Utility [668] Path:            /Applications/Utilities/AirPort Utility.app/Contents/MacOS/AirPort Utility Identifier:      com.apple.airport.airportutility

  • Importing images in Lightroom

    I have just bought Lightroom 4 (upgraded to 4.4). I am trying to import images directly from 2 CF cards in my Canon EOS 7D. On one card I have a mix of JPEG & RAW files (.CR2), on the other only RAW files. Lightroom only sees the JPEG files for impor

  • ESS - Career and Job - Career Profile: Page not found

    Hello, we are facing a problem. When I try to open the Service "Career profile" in subarea "Career" of area "Career and Job" we are getting the error "Page not found or not available". The default-log of the java server lists the following error: #1#

  • How to use my Canon MP540 with Lion Mountain

    Hello i'm on Mountan Lion and i want to use my Printer, Canon MP540 but she is not so old and the system tell me.; We don't find any driver for your printer. Effectively only the 530 and the 560 are supported... Do you have any idea to work withe my