Calling a method within an application?

Hi I'm a student taking an intro Java class and right now I have to develop and application that prompts for someone to input a character of the alphabet and it will display the corresponding number on a telephone that it is listed under. The main method gets the input from the user and we are required to retrieve the corresponding digit to the character from a separate method using either a switch statement or a nested if-then-else statement to determine what the digit is. I'm having trouble calling that method in the main class which is another requirement. any suggestions?
public class Hmwk08
     * Main driver begins program execution.
     * @param args program arguments
    public static void main(String[] args) throws Exception
        char letter;
        char ch;
        int relatesTo;
        PrintStream win = new PrintStream(System.out);
        Scanner in = new Scanner(System.in);
        String newLine = System.getProperty("line.separator");
        win.println("Given a letter of the alphabet, this program" + newLine
                    + "will tell you the corresponding digit on a" + newLine
                    + "telephone keypad.");
        win.println();
        win.print("Enter a letter: ");
        letter = in.nextLine().charAt(0);
        letter = Character.toUpperCase(letter);
     * Get the digit on a telephone keypad that corresponds
     * to the specified character. If the character is neither
     * a letter nor a digit, this method will retun the
     * asterisk character: '*'
     * @param letter the specified character
     * @return the corresponding digit
    private static char getPhoneDigit(char letter)
        char digit;
        digit = '*';
        if(letter == 'A' || letter == 'B' || letter == 'C')
            digit = '1';
        return digit;
}

Your method is static so you can call your method without creating a Hmwk08 object.
char result = getPhoneDigit(letter);Would suffice in your main method
Mel

Similar Messages

  • Calling a method within paint

    Greetings. I am currently writing my major project for computer science. I am just here to ask one question. I called a method from within paint which made my program spit the dummy. The method was supposed to draw a question on the screen but instead it just skipped through many questions as paint was called multiple times. Why would paint have been called multiple times?
    Thankyou

    Thanks for replying. Would you be able to explain
    that in simpler terms?Hardly possible. Paint is painting the component to the screen. Sometimes, what was painted has to be refreshed - if the window moved or was minimized, if something was dragged across it or some other reasons. Whenever that happens, pant() is called.
    By the way, if oyu use Swing, you should not override paint() but paintComponent() to draw something.
    I am studying java without
    swing. I solved the problem by adding a start button
    and putting the method call into action performed,
    but i'm just wondering why it would have mattered
    that it was in paint.Because as you pointed out, paint is called arbitrarily whenever it's needed. Furthermore, it's not the view's task to modify the data model (see MVC pattern) which it did in your case.

  • How to call  Java method from SAPUI5 applications?

    Hi Experts,
        Please give me information that how can I call Java method or jars from SAPUI5 applications?
    Thanks,
    Nag

    Hello Nag,
    why do open this thread in BRM Space? I would suggest reopen this in "UI Development Toolkit for HTML5 Developer Center" Space.
    Regards,
    Tobias

  • How to configure Outlook 2013 to call direct from within the application without using Lync 2013?

    I have Outlook 2013 running on Windows 7 Pro 64-Bit with Lync 2013 (Office 365 Pro). We are using a 3rd party TAPI app from FortiVoice. WE would like to be able to place calls directly from
    within Outlook either by selecting a telephone number within an email and/or via the PEOPLE (Contacts) area.
    What guidelines should we use to enable this feature and not have Lync 2013 intercepting the process i.e. let OUTLOOK handle placing calls?
    Thanks in advance for any feedback provided.

    Hi,
    There seems no solution for this issue so far.
    Here is a fix for older versions of Outlook, maybe worth a try.
    http://support.microsoft.com/kb/959625/en-us
    However, if it doesn’t work, please try Malte’s reply as the workaround in the following thread. See:
    http://social.technet.microsoft.com/Forums/office/en-US/3946f1bb-cc3d-41b6-ab9c-092d62d024d1/outlook-2013-tapi-calling-with-lync-installed?forum=officesetupdeploy
    Thanks.
    Steve Fan
    TechNet Community Support
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Flash call the method of flex application

    In a flex application I use the SWFLoader to load a flash,the code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" fontSize="12">
    <mx:Script>
    <![CDATA[
    import mx.controls.Alert;
    public function testResult():void{
            Alert.show("Hello World");
    ]]>
    </mx:Script>
    <mx:SWFLoader id="flash" source="flash/test3.swf"/>
    </mx:Application>
    There's a button in the embeded flash(flash/test3.swf),
    when I click this button,how to call the the testResult method of the flex application?Thank you!

    Hi,
    You can make use of complete event of SwfLoader and within that function get the instance of Flash Buttonm and register an evnet for the click within the Flex app as shown below:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" fontSize="12">
        <mx:Script>
        <![CDATA[
        import mx.controls.Alert;
        private var loadedSWFMainTimeline:*;
        public function testResult(event:MouseEvent):void{
             Alert.show("Hello World");
        public function onSWFLoadComplete():void {
             //loadedSWFMainTimeline gets you a reference to the Flash SWF MainTimeline
             loadedSWFMainTimeline = flash.content;
             if(loadedSWFMainTimeline)
                var _button:SimpleButton = loadedSWFMainTimeline.flash_button_instance as SimpleButton;
                _button.addEventListener(MouseEvent.CLICK,testResult);       
        ]]>
        </mx:Script>
    <mx:SWFLoader id="flash" source="flash/test3.swf" complete="onSWFLoadComplete();"/>
    </mx:Application>
    Note: In the above code "flash_button_instance" is the instance name of the Flash button.
    If this post answers your question or helps, please kindly mark it as such.
    Thanks,
    Bhasker Chari

  • Calling a method within a class form another class(ViewController)

    I am creating an SQL project in XCODE. I have one view. My main view controller is loading the database to a table/array. I want to add another class (with no NIB) just to handle the display of the table in a UITableView. So, I added a skeleton cocoa touch class file to my classes folder to handle this function when parameters change.
    So, in my app delegate, the "applicationdidFinishLaunchingWithOptions" method loads my mainViewController and NIB.  On the "viewDidLoad" method in my mainViewController, I read a URL into an SQLite database and close the database.  Herein lies the problem: I want to call my new class (TableViewHandler) and pass it the array created in the mainViewController and use the array to populate the UITable.
    How do I call a class from within another class (which has no NIB) to populate the table?  Especially if my TableViewHandler has no "viewDidLoad", "viewDidAppear", etc.
    Regads,
    -Kevin

    This is what my exact problem.
    i've created a bean (DataBean) to access the database. i'm having a servlet program (ShopBook). now to check some details over there in the database from the servlet i'm in need to use a method in the DataBean.
    both ShopBook.java and DataBean.java lies in the package shoppack.
    in ShopBook i tried to instantiate the object to DataBean as
    DataBean db = new DataBean();
    it shows the compiler error, unable to resolve symbol DataBean.
    note:
    first i compiled DataBean.java, it got compiled perfectly and the class file resides inside the shoppack.
    when i'm trying to compile the ShopBook its telling this error.
    hope i'm clear in explaining my problem. can u please help me?
    thank u in advance.
    regards,
    Fazli

  • Adding and Calling custom method to the application module or view object

    My project uses jheadstart 10.1.2.
    I want to run "oracle reports" from my uix page. I have coded a method which takes "VOParameter view object" as a parameter to run report.
    I have generated the input page (parameter page) which based on VOParameter view object, by using jheadstart for using jheadstart lov, date etc. advantages. But I dont know how can I add custom method on application module or view object implementation class and custom button on uix page to call from uix page.
    THANKS for your help

    Yes, method binding has been added to the page UI model.
    I have find some clue that When I darg and drop metod as a submitButton, the code "
    <SubmitButton text="runReport" model="${bindings.runReport}" id="runReport0" event="action" />"
    is added to the uix page code. I change this code like this;
    <button text="runReport" model="${bindings.runReport}" id="runReport0" event="action" onClick="submitForm('dataForm',1,{'event':'action','source':'runReport0'});return false"/>
    by adding onClick method and changed submitButton to button tag..
    Then button action is triggered. But I can not pass to the design part of the uix page. It gives me the message like that "The document is not a valid state" But it works. I dont know why?

  • Calling Java Methods in MXML Application

    Hai ,
    I am new to flex . I want to call a Java Method in my MXML
    Application . Can anyone give a Simple example for this One .
    Thanks
    Madhu

    Thanks. But When i run this Application it throws an Action
    Script Error Like this .
    [RPC Fault faultString="[MessagingError message='Destination
    'myObject' either does not exist or the destination has no channels
    defined (and the application does not define any default
    channels.)']" faultCode="InvokeFailed" faultDetail="Couldn't
    establish a connection to 'myObject'"]
    at mx.rpc::AbstractInvoker/
    http://www.adobe.com/2006/flex/mx/internal::invoke()[E:\dev\3.0.x\frameworks\projects\rpc\ src\mx\rpc\AbstractInvoker.as:257
    at mx.rpc.remoting.mxml::Operation/
    http://www.adobe.com/2006/flex/mx/internal::invoke()[E:\dev\3.0.x\frameworks\projects\rpc\ src\mx\rpc\remoting\mxml\Operation.as:197
    at
    mx.rpc.remoting::Operation/send()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\remotin g\Operation.as:113]
    at Function/
    http://adobe.com/AS3/2006/builtin::apply()
    at
    mx.rpc.remoting.mxml::Operation/send()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\re moting\mxml\Operation.as:170]
    at Function/
    http://adobe.com/AS3/2006/builtin::apply()
    at mx.rpc::AbstractService/
    http://www.adobe.com/2006/actionscript/flash/proxy::callProperty()[E:\dev\3.0.x\frameworks \projects\rpc\src\mx\rpc\AbstractService.as:285
    at s2/___s2_Button1_click()[C:\Workshop for eclipse\work
    space\Flex\DCSearch\flex_src\s2.mxml:6]
    Can u help me
    Madhu

  • Calling custom methods from Nested Application Modules

    We are having a problem with passing parameters to our nested App Modules.
    We have a custom method in our nested app module and when we drag that method from our data control palette in our page everything seems to work just fine. We are binding our NamedData values to #{requestScope.<field>} where the fields are inputText controls. When we run it will execute the function but the parameters are null.
    It seems to me that the Nested App Module can not evaluate the EL expression, or in other words when it gets evaluated it returns a null.
    Can anyone help with this?
    Thanks,
    Peter

    If you use an EL expression of some hard-coded value instead of #{requestScope.XXX} does that value correctly get passed to the function?
    In other words, are you 100% sure that EL expression is not evaluating to null ?
    If you drop an AM method as a parameter form on a page, you'll see that by default it's NamedData elements use EL expressions that reference attribute bindings that are bound to local page-def variables, rather than to #{requestScope.something}

  • Trying to understand methods - calling methods within own class - help

    I'm trying to write a simple program to search for letters in a string. I'm having a ton op problems; java seems so complicated with a lot of rules.
    The main problem I'm having (for now) is calling a method within the same class as main.
    import java.io.*;
    class LookForLetters{
        public static void main(String[] args)
         int i = 0;     
         int j = 0;
         int l = 0;
         int m = 0;
         String question1 = "Enter the line to be searched"; 
         String question2 = "Enter the line to be searched";       
         returnResponse stringtosearch = new returnResponse(question1); // here's where my problem is
            char[] chartosearch = stringtosearch.toCharArray();
         returnResponse letterstofind = new returnResponse(question2);
            char[] chartofind = letterstofind.toCharArray();     
         int findlength = chartosearch.length();
         int searchlength = chartofind.length();
         int[] k = new int[searchlength];
         for(i = 0; i < findlength; i++)
             for(j = 0; j < searchlength; j++)   
              if(chartosearch[i] == chartofind[j])
                  k[l] = i;
                  l++;
                  System.out.print("T");
             System.out.print(i + " " + l);
                if(l == 0)
                    System.out.print(chartofind[i] + " is the not in the sentence.");
                    System.out.println();       
                else
                    System.out.print(chartofind[i] + " is the ");
                 for(m = 0; m < l; m++)
                     System.out.print(k[l] + " ");
                    System.out.print("letter of your sentence");
                    System.out.println();
                    l = 0;
        public String returnResponse(String question){
         String response = " ";
         System.out.print(question);
         try
             InputStreamReader isr = new InputStreamReader(System.in);
                BufferedReaderbr = new BufferedReader(isr);
             response = br.readLine();            
         catch(IOException e)
             System.out.print("error");
         return response;
    }The compiler says that it can't find the returnResponse method. when I try to instantiate the whole class, it says the package is not included. Please help.

    JoachimSauer wrote:
    DaneWKim wrote:
    thank you very much for your response. I'm sure it's obvious that I'm really confused. I'm used to C and assembly programming, so the OO concepts are really foggy.That particular line doesn't even deal with any OO concept. But the fact that you already know C helps me give a (hopefully) more useful answer:
    What is the return type of the method you're trying to call?
    What is the type of the variable you want to assign the return value to?
    Are those compatible? Or even more general: do they both exist?I changed it to:
            String stringtosearch = returnResponse(question1);
            char[] chartosearch = stringtosearch.toCharArray();
         String letterstofind = returnResponse(question2);
            char[] chartofind = letterstofind.toCharArray();I guess I'm getting confused with medthods, class and types. There's a whole host of new vocabulary and rules with OO and java that have me a bit confused. I appreciate your help.

  • ADF Groovy call method in different application module

    Hi All,
    I have two different application modules(Say TestAM.xml and MyTestAM.xml). I have a method in second application module. I want to call that method from Entity object. Normally we use adf.object.applicationModule.getName()  if it is in the first application module
    So how do I call a method in second application module from Entity object?
    I am using JDev 11.1.1.5 and ADF BC.
    Thanks,
    Rajesh

    Hi,
    In my opinion the second way have a advantage, which its method could be invoke automatically using a invokeAction on pageDef, if necessary.
    regards

  • Can't add list element when calling a method from another class

    I am trying to call a method in another class, which contains code listmodel.addElement("text"); to add an element into a list component made in that class.
    I've put in System.out.println("passed"); in the method just to make sure if the method was being called properly and it displays normally.
    I can change variables in the other class by calling the method with no problem. The only thing I can't do is get listmodel.addElement("text"); to add a new element in the list component by doing it this way.
    I've called that method within it's class and it added the element with no problem. Does Java have limitations about what kind of code it can run from other classes? And if that's the case I'd really like to know just why.

    There were no errors, just the element doesnt get added to the list by doing it this way
    class showpanel extends JPanel implements ActionListener, MouseMotionListener {
           framepanel fp = new framepanel();
           --omitted--
         public void actionPerformed(ActionEvent e){
                  if(e.getSource() == button1){
                       fp.addLayer();
    /*is in a different class file*/
    class framepanel extends JPanel implements ActionListener{
            --omitted--
         public void addLayer(){
              listmodel.addElement("Layer"+numLayer);
              numLayer++;
    }

  • NoSuchMethodError when call JPublisher method

    Im getting a java.lang.NoSuchMethod error when calling a method within
    a Java class generated by JPublisher.

    Hi Larry,
    thanks for the answer:
    DB Version is:
    select * from v$version:
    SQL> select * from v$version;
    BANNER
    Oracle9i Enterprise Edition Release 9.0.1.4.0 - 64bit Production
    PL/SQL Release 9.0.1.4.0 - Production
    CORE     9.0.1.2.0     Production
    TNS for IBM/AIX RISC System/6000: Version 9.0.1.4.0 - Production
    NLSRTL Version 9.0.1.4.0 - Production
    Is there a possibility to get out if intermedia is installed? I really think it is because the methods work. I can process the image - the problem is that somehow a error occurs but the the method worked. The image written to the filesystem has the correct values.
    describe ordsys.ordimage leads to the expected output:
    SQL> describe ordsys.ordimage;
    Element Type
    SOURCE ORDSYS.ORDSOURCE
    HEIGHT INTEGER
    WIDTH INTEGER
    CONTENTLENGTH INTEGER
    FILEFORMAT VARCHAR2(4000)
    CONTENTFORMAT VARCHAR2(4000)
    COMPRESSIONFORMAT VARCHAR2(4000)
    MIMETYPE VARCHAR2(4000)
    INIT FUNCTION
    COPY PROCEDURE
    PROCESS PROCEDURE
    PROCESSCOPY PROCEDURE
    SETPROPERTIES PROCEDURE
    CHECKPROPERTIES FUNCTION
    GETHEIGHT FUNCTION
    GETWIDTH FUNCTION
    GETFILEFORMAT FUNCTION
    GETCONTENTFORMAT FUNCTION
    GETCOMPRESSIONFORMAT FUNCTION
    SETLOCAL PROCEDURE
    CLEARLOCAL PROCEDURE
    ISLOCAL FUNCTION
    GETUPDATETIME FUNCTION
    SETUPDATETIME PROCEDURE
    GETMIMETYPE FUNCTION
    SETMIMETYPE PROCEDURE
    GETCONTENTLENGTH FUNCTION
    GETCONTENT FUNCTION
    GETBFILE FUNCTION
    DELETECONTENT PROCEDURE
    SETSOURCE PROCEDURE
    GETSOURCE FUNCTION
    GETSOURCETYPE FUNCTION
    GETSOURCELOCATION FUNCTION
    GETSOURCENAME FUNCTION
    IMPORT PROCEDURE
    IMPORTFROM PROCEDURE
    EXPORT PROCEDURE
    PROCESSSOURCECOMMAND FUNCTION
    OPENSOURCE FUNCTION
    CLOSESOURCE FUNCTION
    TRIMSOURCE FUNCTION
    READFROMSOURCE PROCEDURE
    WRITETOSOURCE PROCEDURE
    MIGRATEFROMORDIMGB PROCEDURE
    MIGRATEFROMORDIMGF PROCEDURE
    GETPROPERTIES PROCEDURE
    I do not want to use a database link. everything is stored in that one database. I really have no clue why plsql thinks I want to.
    Regards,
    Markus

  • Calling a method in a component from main application

    Hi,
    I have a mxml component( menu1.mxml) . In the menu1.mxml
    there is a include for the actionscript file(menu1.as). In the main
    application page(SampleLogin.mxml) I want to call the method in the
    btnSubmit_Click() on the saveIndex() method for case 0. I am
    attaching all the code below

    case 0:
    menuOne.btnSubmit_Click( );
    break;
    Also it would probably be following best practices to used a
    custom event to pass the information in your "LoginButton_Click()"
    function to the application.

  • EJB 3.1 @Asynchronous and calling other methods from within

    Hey all,
    I am helping a friend set up a test framework, and I've turned him on to using JEE6 for the task. I am decently familiar with entity beans, session beans, and such. One of the new features is @Asynchronous, allowing a method to be ran on a separate thread. The test framework generally needs to spawn potentially 1000's of threads to simulate multiple users at once. Originally I was doing this using the Executor classes, but I've since learned that for some reason, spawning your own threads within a JEE container is "not allowed" or bad to do. I honestly don't quite know why this is.. from what I've read the main concern is that the container maintains threads and your own threads could mess up the container somehow. I can only guess that this might be possible if your threads use the container services in some way.. but if anyone could enlighten me on the details as to why this is bad, that would be great.
    None the less, EJB 3.1 adds the async capability and I am now looking to use this. From my servlet I use @EJB to access the session bean, and call an async method. My servlet returns right away as it should. From the async method I do some work and using an entity bean store results, so I don't need to return a Future object. In fact, my ejb then makes an HttpClient call to another servlet to notify it that the result is ready.
    My main question though, is if it's ok to call other methods from the async method that are not declared @Asynchronous. I presume it is ok, as the @Asynchronous just enables the container to spawn a thread to execute that method in. But I can't dig up any limitations on the code within an async method.. whether or not it has restrictions on the container services, is there anything wrong with using HttpClient to make a request from the method.. and making calls to helper methods within the bean that are not async.
    Thanks.

    851827 wrote:
    Hey all,.. from what I've read the main concern is that the container maintains threads and your own threads could mess up the container somehow. I can only guess that this might be possible if your threads use the container services in some way.. but if anyone could enlighten me on the details as to why this is bad, that would be great.
    Yes since the EE spec delegated thread management to conatiners, the container might assume that some info is available in the thread context that you may not have made available to your threads.
    Also threading is a technical implementation detail and the drive with the EE spec is that you should concentrate on business requirements and let the container do the plumbing part.
    If you were managing your own threads spawned from EJBs, you'd have to be managing your EJBs' lifecycle as well. This would just add to more plumbing code by the developer and typically requires writting platform specific routines which the containers already do anyway.
    >
    None the less, EJB 3.1 adds the async capability and I am now looking to use this. From my servlet I use @EJB to access the session bean, and call an async method. My servlet returns right away as it should. From the async method I do some work and using an entity bean store results, so I don't need to return a Future object. In fact, my ejb then makes an HttpClient call to another servlet to notify it that the result is ready.
    My main question though, is if it's ok to call other methods from the async method that are not declared @Asynchronous. I presume it is ok, as the @Asynchronous just enables the container to spawn a thread to execute that method in. But I can't dig up any limitations on the code within an async method.. whether or not it has restrictions on the container services, is there anything wrong with using HttpClient to make a request from the method.. and making calls to helper methods within the bean that are not async.
    Thanks.If you want to be asynchronous without caring about a return value then just use MDBs.
    The async methods have no restrictions on container services and there is nothing wrong with calling other non async methods. Once the async method is reached those annotations don't matter anyway (unless if you call thhose methods from a new reference of the EJB that you look up) as they only make sense in a client context.
    Why do you need to make the call to the servlet from the EJB? Makes it difficult to know who is the client here. Better use the Future objects and let the initial caller delegate to the other client components as needed.

Maybe you are looking for