Call a java class

I have a fairly simple problem. I am making a basic game just for a learning experience.
Project = 2ndif
I have 2 classes in the project GuessingGame, and Town. After I finish with GuessingGame I need it to call Town.java class. Any suggesions. I put a note where I need to call Town.java
I'm not 100% sure on how to ask for what I need. Not too fluent with the lingo yet.
import static java.lang.System.out;
import java.util.Scanner;
import java.util.Random;
class GuessingGame {
     public static void main(String args[]) {
          Scanner myScanner = new Scanner(System.in);
          out.println("Rolling stats... ");
          //Variables for stats
          int RandomNumber = 0;
          int Strength = 0;
          int Dexterity = 0;
          int Inteligence = 0;
          int Wisdom = 0;
          int Charisma = 0;
          int Counter = 0;
          int reroll = 1;
          //Reroll if stats are not desireable
          for (reroll=reroll; reroll==1;) {
               RandomNumber = 0;
               Strength = 0;
               Dexterity = 0;
               Inteligence = 0;
               Wisdom = 0;
               Charisma = 0;
               Counter = 0;
          //3D6 rolls redo 1 if its first roll
               for ( Counter=Counter; Counter<3; Counter++ ) {
                    RandomNumber = new Random() .nextInt(6) + 1;
                    if (RandomNumber == 1) {
                         RandomNumber = new Random() .nextInt(6) + 1;
                         Strength = Strength + RandomNumber;                
          Counter = 0;
          //3D6 rolls redo 1 if its first roll
               for ( Counter=Counter; Counter<3; Counter++ ) {
                    RandomNumber = new Random() .nextInt(6) + 1;
                    if (RandomNumber == 1) {
                         RandomNumber = new Random() .nextInt(6) + 1;
                         Dexterity = Dexterity + RandomNumber;
          Counter = 0;
          //3D6 rolls redo 1 if its first roll
               for ( Counter=Counter; Counter<3; Counter++ ) {
                    RandomNumber = new Random() .nextInt(6) + 1;
                    if (RandomNumber == 1) {
                         RandomNumber = new Random() .nextInt(6) + 1;
                         Inteligence = Inteligence + RandomNumber;
          Counter = 0;
          //3D6 rolls redo 1 if its first roll                    
               for ( Counter=Counter; Counter<3; Counter++ ) {
                    RandomNumber = new Random() .nextInt(6) + 1;
                    if (RandomNumber == 1) {
                         RandomNumber = new Random() .nextInt(6) + 1;
                         Wisdom = Wisdom + RandomNumber;
          Counter =0;
          //3D6 rolls redo 1 if its first roll
               for ( Counter=Counter; Counter<3; Counter++ ) {
                    RandomNumber = new Random() .nextInt(6) + 1;
                    if (RandomNumber == 1) {
                         RandomNumber = new Random() .nextInt(6) + 1;
                         Charisma = Charisma + RandomNumber;
          //Show stats
          out.println("Strength = " + Strength);
          out.println("Dexterity = " + Dexterity);
          out.println("Inteligence = " + Inteligence);
          out.println("Wisdom = " + Wisdom);
          out.println("Charisma = " + Charisma);
          out.println("");
          out.print("Reroll stats? 1 = yes 2 = no: ");
          reroll = myScanner.nextInt();
          out.println("");
          out.println("");
          *******THIS IS WHERE I NEED TO CALL TOWN.JAVA*********
}

//Show stats
          out.println("Strength = " + Strength);
          out.println("Dexterity = " + Dexterity);
          out.println("Inteligence = " + Inteligence);
          out.println("Wisdom = " + Wisdom);
          out.println("Charisma = " + Charisma);
          out.println("");
          out.print("Reroll stats? 1 = yes 2 = no: ");
          reroll = myScanner.nextInt();
          out.println("");
          out.println("");
          *******THIS IS WHERE I NEED TO CALL TOWN.JAVA*********
}It seems like you are confused as to how to use your Town class. Java gives you the freedom to run an entire program in the main method like you are doing.. even if its not elegant. However, if you are going to continue your program as you are doing it in the main method. you probably want to do something like this.
//Show stats
          out.println("Strength = " + Strength);
          out.println("Dexterity = " + Dexterity);
          out.println("Inteligence = " + Inteligence);
          out.println("Wisdom = " + Wisdom);
          out.println("Charisma = " + Charisma);
          out.println("");
          out.print("Reroll stats? 1 = yes 2 = no: ");
          reroll = myScanner.nextInt();
          out.println("");
          out.println("");
          /*******THIS IS WHERE YOU BEGIN TO USE A TOWN*********/
                Town town = new Town();  // creates a new town
                 /* Here you start to do whatever it is you want to do with your newly created town...*/
                 town.addNewCharacter(Strength, Dexterity, Inteligence, Wisdom, Charisma);
                 town.whateverActionYouWantToDoWithYourTown();
}

Similar Messages

  • How can I call a java class from within my program?

    I was wondering if there's a platform independent way to call a java class from my program.

    Here's my scenario. I'm working on a platform independent, feature rich, object-oriented command prompt program. The way I'm designing it is that users can drop classes they write into my bin directory and gain access to the class through my program. For example, they drop a class named Network.class in the bin directory. They would type Network network at my command prompt and gain access to all the methods available in that class. They can then type system.echo network.ipaddress() at my prompt and get the system's ip address. I have it designed that there's a server running in the background and the clients connect to my port. Once connected the end-user can enter their user name and password and gain access to the system. When they type a command they actually call another java program which connects to my server using a seperate thread. They can then communicate back and forth. I have it set that everything has a process id and it's used to keep track of who called what program. Once the program is done it disconnects and closes. Rather than getting into the nitty gritty (I didn't want to get into heavy detail, I know how everything will work) I'm really interested in finding out how I can call a java program from my program. I don't want it to be part of the app in any way.

  • How to call a Java class from another java class ??

    Hi ..... can somebody plz tell me
    How to call a Java Class from another Java Class assuming both in the same Package??
    I want to call the entire Java Class  (not any specific method only........I want all the functionalities of that class)
    Please provide me some slotuions!!
    Waiting for some fast replies!!
    Regards
    Smita Mohanty

    Hi Smita,
    you just need to create an object of that class,thats it. Then you will be able to execute each and every method.
    e.g.
    you have developed A.java and B.java, both are in same package.
    in implementaion of B.java
    class B
                A obj = new A();
                 //to access A's methods
                 A.method();
                // to access A's variable
                //either
               A.variable= value.
               //or
               A.setvariable() or A.getvariable()

  • How to call a java class in a bat file

    Hi
    I need to call a Test.java class in a bat files .It refer .DOM.jar
    in C:/url; How do i call the java class i need the syntax
    Thanks lot

    assuming lanch.bat, Test.class and DOM.jar are in c:\url
    assuming %JAVA_HOME% is defined (else substitue it with your java installation directory)
    here is the content of launch.bat:
    cd C:/url (or cd c:\url ) (or cd c: followed by cd url)
    %JAVA_HOME%\bin java -classpath .;DOM.jar Test
    hop that'd help,
    marvinrouge

  • Java.lang.NoClassDefFoundError while calling a java class from BPEL

    Hi,
    I'm calling a java class to convert JSON to XML using BPEL. I have imported all the necessary jar files in the project and compiling done successfully.
    But at runtime , i get the java.lang.NoClassDefFoundError: net/sf/json/JSON error.
    For this i placed all the necessary jars under FUSION_HOME/Oracle_SOA1/soa/modules/oracle.soa.ext_11.1.1/ path and restarted the server.
    But still i'm getting the same error at runtime.
    Did i missed any step? Let me know the procedure to solve this.
    Do i have to run ant or edit Manifest file after placing the jar?
    in one site i find we have to place the jars under <DOMAIN HOME>/lib directory. Is this correct?
    We are using SOA suite 11.1.1.6.
    Thanks,
    Terry

    Hi Karan,
    I have done placing the jars at FUSION_HOME/Oracle_SOA1/soa/modules/oracle.soa.ext_11.1.1/ and ran ant  -f build.xml .The build was successful without any error.
    I have even placed the jars in <DOMAIN HOME>/lib (/us2001/fmw/11.1.1.6/user_projects/domains/ohsdomain/lib) and did a server restart.
    After these activities, when i execute the composite, i still get the error in em console,
    Message
    got RuntimeException
    Supplemental Detail
    oracle.fabric.common.FabricException: Could not create object of class 'packageName.className'; nested exception is:
    java.lang.NoClassDefFoundError: net/sf/json/JSON
    at oracle.integration.platform.blocks.wsif.WsifReference.request(WsifReference.java:698)
    at oracle.integration.platform.blocks.mesh.SynchronousMessageHandler.doRequest(SynchronousMessageHandler.java:139)
    at oracle.integration.platform.blocks.mesh.MessageRouter.request(MessageRouter.java:182)
    Any help on this.
    Thanks,
    Terry

  • Calling a Java Class from PL/SQL

    Hai,
    I need a technique of calling a class file and invoke its
    methods written in Java by PL/SQL for my intranet development.
    PLease let me know if you have really experienced and won.
    Thanks
    JOhnson

    First, to call a Java class from PL/SQL the class needs to be
    deployed to the database. you can check the 8i documentation for
    the instructions for loading Java into the database(LoadJava).
    The document contains information on how to load the Java and
    call it from PL/SQL. The following links should help.
    Loading Java:
    http://otn.oracle.com/docs/products/oracle8i/doc_library/817_doc/
    java.817/a83728/03write6.htm
    Invoking a Java Method in the database:
    http://otn.oracle.com/docs/products/oracle8i/doc_library/817_doc/
    java.817/a83728/04jserv2.htm
    Gary (JDev Team)

  • I want to call External Java class from the PL/SQL

    Hi,
    I am using Oracle Apps R11i (11.5.7), I wanted to call external Java class from the PL/SQL. This external Java class is residing in another application server.
    How do I do this.
    I know one way. Develop C routine in Oracle Apps to call external java class and call this C routine from the PL/SQL.
    Is there any simple method available? or any other method?
    Thanks in advance.
    -Venkat

    First of all, this is a Java application you're talking about, right (i.e. it has a main() function)? It's not just a class that you're trying to instantiate is it? If it's an application, you obviously have to start a new virtual machine to run it (rather than using the virtual machine built into the database like stored java). I'm a little leary of your mention of an "application server" as this would more commonly mean that a virtual machine is already over there running with access to this class. In which case, you'd typically interface with SOAP or some other RPC API.
    All that aside, as long as you have physical disc access (through NFS or whatever) to the class file, you could use a java wrapper class with a system call to do this. In fact, there is a thread in just the last day or so on this very forum that has the code to do just that (see " Invoking OS Commands from PL/SQL"). However, it's worth noting that the virtual machine will be running on the database server in this case and not the application server.

  • Calling a java class in JSP in Weblogic 5.1

    Hi
    I am trying to call a java class in a jsp page. But it is giving an error:
    Compilation of 'C:\weblogic\myserver\classfiles\jsp_servlet\_knet\_buy.java' failed:
    C:\weblogic\myserver\classfiles\jsp_servlet\_knet\_buy.java:79: cannot access jsp_servlet._knet.e24PaymentPipe
    probably occurred due to an error in /knet/buy.jsp line 25:
    e24PaymentPipe pipe = new e24PaymentPipe();
    Is this a problem bcos of the wrong path of the class file which i am calling?
    Please help this is urgent

    Hello All
    As I tried to deploy the easiest project (dummy.war) on WebLogic 8.1.5, There is only one class (without package) Login.class
    *********** Listing of the dummy WAR ***********
    META-INF/
    META-INF/MANIFEST.MF
    WEB-INF/
    WEB-INF/classes/
    WEB-INF/classes/Login.class
    WEB-INF/web.xml
    index.jsp
    login.jsp
    ************ Output of deployment from Admin Console****************
    Log:     
         A log of the task's activities.
    [Deployer:149033]preparing application dummy on intranetAdmin
    [Deployer:149033]prepared application dummy on intranetAdmin
    [Deployer:149033]activating application dummy on intranetAdmin
    [Deployer:149033]failed application dummy on intranetAdmin
    [Deployer:149034]An exception occurred for task [Deployer:149026]
    Deploy application dummy on intranetAdmin.:
    Exception:weblogic.management.ApplicationException: start() failed.
    Module: dummy Error: weblogic.management.DeploymentException:
    [HTTP:101216]Servlet: "index" failed to preload on startup in Web application:
    " dummy ".
    weblogic.servlet.jsp.CompilationException: Compilation of D:\apps\wlsapp\
    INTRAN~1\.\intranetAdmin\.wlnotdelete\extract\intranetAdmin_ dummy _ dummy
    \jsp_servlet\__index.java failed.
    D:\apps\wlsapp\INTRAN~1\.\intranetAdmin\.wlnotdelete\extract\
    intranetAdmin_dummy_dummy\jsp_servlet\__index.java:22: '.' expected
    import Login; //[ /login.jsp; Line: 8]
    ^
    1 error
    at weblogic.servlet.jsp.JspStub.compilePage(JspStub.java:478)
    at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:246)
    at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:196)
    at weblogic.servlet.internal.WebAppServletContext.preloadServlet(WebAppServletContext.
    java:3430)
    at weblogic.servlet.internal.WebAppServletContext.preloadServlets(WebAppServletContext.
    java:3387)
    at weblogic.servlet.internal.WebAppServletContext.preloadServlets(WebAppServletContext
    .java:3373)
    at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:3356)
    at weblogic.servlet.internal.WebAppServletContext.setStarted(WebAppServletContext.java:
    6208)
    at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:864)
    at weblogic.j2ee.J2EEApplicationContainer.start(J2EEApplicationContainer.java:2134)
    at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:2175)
    at weblogic.management.deploy.slave.SlaveDeployer$ComponentActivateTask.
    activateContainer(SlaveDeployer.java:2520)
    at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.doCommit(SlaveDeployer
    .java:2438)
    at weblogic.management.deploy.slave.SlaveDeployer$Task.commit(SlaveDeployer.java:2155)
    at weblogic.management.deploy.slave.SlaveDeployer$Task.checkAutoCommit(SlaveDeployer.java:2254)
    at weblogic.management.deploy.slave.SlaveDeployer$Task.prepare(SlaveDeployer.java:2149)
    at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.prepare(SlaveDeployer.
    java:2401)
    at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer.java:
    883)
    at weblogic.management.deploy.slave.SlaveDeployer.prepareDelta(SlaveDeployer.java:591)
    at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java:500)
    at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:25)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
    Caused by: java.io.IOException: Compiler failed executable.exec
    at weblogic.utils.compiler.CompilerInvoker.compileMaybeExit(CompilerInvoker.java:470)
    at weblogic.utils.compiler.CompilerInvoker.compile(CompilerInvoker.java:328)
    at weblogic.utils.compiler.CompilerInvoker.compile(CompilerInvoker.java:336)
    at weblogic.utils.compiler.CompilerInvoker.compile(CompilerInvoker.java:321)
    at weblogic.servlet.jsp.JspStub.compilePage(JspStub.java:451)
    ... 22 more
    - with nested exception:
    [java.io.IOException: Compiler failed executable.exec]
    I put this class into a dummy package named sample, changed package declaration within this class and changed import statement within jsp pages like this :
    <%@ page import="sample.Login " %>
    <jsp:useBean id="logUsr" scope="session" class="sample.Login" />
    When I did like this, everything is ok. No more exception.
    If my application has so many java classes under WEB-INF/classes/ without creating package, it may be so inconvenience.
    Please kindly let me know why this exception (class not found exception) occurred.
    And what is the solution? I cannot deploy the application successfully yet.
    many thanks,
    Zin Ko Win

  • Calling a java class in a JSP file

    Hello,
    I have a jsp file in which I call a java class.
    I work with Tomcat 4.0.1
    If I modify the java class and then I execute my JSP, it still be the old version of my class that is executed.
    I don't understand why since if I creates a main function and I execute it, it works correctly!
    Do you know what is the problem?
    Thanks

    i also have this problem.when i modify jsp file,it didn't execute inmediately. Then i restart tomcat,but problem also exist.
    a few minute age,i execute jsp file again,it can appear the modified jsp.i don't down why
    i work tomcat 5.0 windowxp

  • Jsp session variable to call in  java class.

    here i am facing a problem in calling a jsp session varibale to java class.
    in my code.. i have seperate files for jsp pages and packaged java classes.
    as i am developing a web tire application. the data entered in the front end i am getting to jsp page and putting the mandatory in session to use in other pages. now here the same session vaiable i have to use/call in java class file.
    Please refer me the best method and any references on this to call the session vaiable to java class file.
    in jsp page i decleared like this:
    session.setAttribute("stuIdentification",stuid);
    this id i have to use in java class.file.
    how to call it?
    Thanks
    Kurra

    Gimbal2's got the right idea.
    The reasons for choosing point 1) are also valid. Whenever possible try and do as much code that is not specifically tied to your business objects inside your dynamic element (the jsp page) instead of your static one (the compiled class)
    this allows you to very easily update your jsp to make any changes without having to recompile class code. Recompiling seems like a little thing when you are in development but imagine if the class is executed by a business critical application that faces forward to customers, recompiling will mean shutting down your servers and that may not be an option.
    Regards,
    David

  • Calling my Java class from JSP page

    Hello, I am trying to call my Java class from my JSP page passing parameters to it and getting back a collection of result sets. Can someone tell me what I might be doing wrong:
    JSP code to call Java class:
    <%
    String strEssUser = "test";
    String strProcessingMonth = "JUL";
    String strProcessingYear = "2002";
    strQueryList=new ListReturn(strEssUser.toString(), strProcessingMonth.toString(), strProcessingYear.toString());
    %>
    I get this error when I try to run this JSP page using tomcat:
    C:\Program Files\Apache Tomcat 4.0\work\Standalone\localhost\em\jsp\Test_0005fSummarySBU_0005fscreen$jsp.java:77: Class org.apache.jsp.ListReturn not found.
    strQueryList=new ListReturn(strEssUser.toString(), strProcessingMonth.toString(), strProcessingYear.toString());
    I'm not sure if this problem is the way I am calling the Java class, or if I have a problem in the Java code itself. Can anyone help?

    Ok, I get a very strange error now:
    org.apache.jasper.JasperException: Unable to compile class for JSPerror: An error has occurred in the compiler; please file a bug report (http://java.sun.com/cgi-bin/bugreport.cgi).
    What is this??? Anyone?

  • Problem Calling a Java class from PLSQL function

    We are calling a Java class through oracle function as
    FUNCTION CalculateAMW (contributorid IN Number,
    fromdate IN Date,OHorAnncoverage in Number,
    OHAnncoverage in Number,
    AppStatus in Number,
    Status in Number)
    RETURN Number
    AS LANGUAGE JAVA
    NAME 'AMWCalculations.calculateAMW
    (long,java.sql.Timestamp,long,long,long,long) return double';
    on execution of this function the sql prompt for the 1st time it is giving the output
    but
    if reexecute it is throwing and error ORA - 932 : Inconsistent
    datatypes.
    Recompiling the java class then it works for the 1st time and the next
    time
    we execute it throws error as explained above.
    What could be the problem.
    Thanks
    Nanda Kishore

    any idea???Yes, you are in the wrong forum, this is a Java forum, you have an ASP question, so i suggest you visit an ASP forum/site

  • 11g iBots(Agents) calling custom java class?

    We upgraded from 10g to 11g and we have iBots that call a custom java class in the form of a jar file.
    This all worked fine in 10g.
    I followed all configuration steps in the documentation, but we are unable to get our iBots(Agents) to work in 11g.
    Keep getting "Can't find Class" errors.
    Has anyone successfully created agents that call custom java classes with 11g, if so, can you please share your steps for doing this?

    Hi glova,
    The document refers to the RPD and catalog migration....what ever customization used in 10g wont effect in 11g i suppose most of the things.
    i would suggest you to copy the java class of ibots and do the copy paste or manually do it in 11g and see if it works ...this is the only alternative.
    hope helps you.
    Cheers,
    KK

  • How do you call a java class from the main method in another class?

    Hi all,
    How do you call a java class from the main() method in another class? Assuming the two class are in the same package.
    Thanks
    SI
    Edited by: okun on May 16, 2010 8:40 PM
    Edited by: okun on May 16, 2010 8:41 PM
    Edited by: okun on May 16, 2010 8:47 PM

    georgemc wrote:
    To answer your impending question, either the method you're calling has to be static, or you need an instance of that other class to invoke it against. Prefer the latterAnd to your impending question after that: no, don't use the Singleton pattern.

  • Calling a java class from abap/bsp

    Hello,
    I am still learning ABAP. I need to call a java class (a chart drawing library) from ABAP or from a BSP. What is the best way to do that ?
    Basically I would create an object, pass data from a database and then get some binary data from that object (an image).
    Hope you can help me
    Sincerely,
    Olivier Matt

    /people/gregor.wolf3/blog/2004/08/26/setup-and-test-sap-java-connector-outbound-connection
    check the above  link and this forum too
    Call Java Class and Methods from ABAP

  • Call a java class when deleting a user

    Hi,
    I have identified the "Deprovision Form" as the form used when you want to delete a user. What I would to do is invoke a java class when you press on OK on the delete user page.
    thanks in advance.

    You can try to call the java class in a Field's Expansion block by putting the condition that
    <cond>
    <eq>
    buttonValue
    OK
    <eq>
    then call java....

Maybe you are looking for

  • Photoshop Help Opens By Itself

    This has been reported before but the topic was closed. I am having an issue where Photoshop CS6 is opening 4 tabs in Chrome that all go to http://helpx.adobe.com/photoshop/topics.html whenever I click anywhere on the screen. This began when I was us

  • ITunes won't show info on the iPod menu.

    All the buttons, pulldowns, playlists, and menus are blank. The iPod will sync, but I cannot see any of the options to adjust how it syncs.  I beleive it is a 3rd Gen Nano.

  • Oracle 11.1.0.6 to 11.1.0.7 on Solaris SPARC experience

    Have anyone made this update yet ? Do you have any recommandation ? Should I apply Sun's patch cluster first ? Thanks.

  • Freight based on order value before tax

    Similar  to the post regarding freight charges which are conditional on shipping address ( which looked as if customisation was the only route) , is there an easy way to implement an order value cut-off point on freight charges. ( i.e. orders below a

  • Indesign CS 3.0.1

    I want to create text in a circle. The directions say to select the text path tool. I can't find it. Where is it? Arlene