Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Need help with calling methods from classes - Java Assignment

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help with calling methods from classes - Java Assignment

    I'm working through a Java assignment for school, and I've hit a road block about half way through it. The part I'm up to is asking me to add a method to a seperate .java file (MyString.java in this case) and then to call that method in my main program file. Don't get too confused with how the assignment is meant to work or anything, I only really need help with the code to call that method in my main file. I'm going to show you the relevant areas of code in both files and I'm hoping someone can help me out with the code to call that method from the class MyString.java.

    Ok, here is the section taken from the class MyString.java:

    public static String createID(C)
       {
          String message = C.substring(0.3).toUpperCase();
          return message+= (int) (Math.random()*99 + 1200);
       }

    Basically what that's going to do is take the first three characters from the lastName field and merge them with a random number between 1200 - 1299 to create an Employee ID.

    My problem is I really have no idea how to call this method in my main file below:

    public static void createEmpID()
        {
            //JOptionPane.showMessageDialog(null,"In (2) createEmpID()"); <-- This is just filler text, I need the code for this part that will call the previously mentioned method.
        }

    I hope I've made this as clear as possible but if you need any further clarification let me know and I'll respond as soon as possible.

    Thanks for taking the time to read my post and I hope to hear from someone soon.


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Need help with calling methods from classes - Java Assignment

    It is a static method, so you'll call it on the class:

    MyString.createID(someStringGoesHere)

    Note though that you must take care to spell and capitalize all your variable, method and class names precisely.

Similar Threads

  1. Calling upon methods
    By jonathanfox in forum Java Theory & Questions
    Replies: 4
    Last Post: August 3rd, 2012, 11:58 AM
  2. Why and where abstract methods & classes and static methods are used?
    By ajaysharma in forum Object Oriented Programming
    Replies: 7
    Last Post: July 14th, 2012, 01:16 AM
  3. [SOLVED] Calling methods from other classes
    By knightknight in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 7th, 2011, 06:16 PM
  4. Calling worker methods in JSF.
    By newbie in forum Web Frameworks
    Replies: 0
    Last Post: March 18th, 2011, 02:21 PM
  5. Calling for methods
    By soccer_kid_6 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 1st, 2010, 12:13 AM