Java Library
Hey guys,
I'm working on a guess my number program and I need to create a library which contains a method which will then be used by main to pick a secret random number.
I've created the library but when I compile everything and test it out (from my main method), I get compile errors.
I'm only going to be calling GuessMyNumber() for now with this program
Did I use it correctly? I'm trying to make it pick a random number from 1 to 1000
package library;
public class Gamble
// returns either "heads" or "tails"
public static String flipCoin( )
int flipCode = (int)(2*Math.random()); // picks a 0 or a 1
if(flipCode==0)
return "heads";
else
return "tails";
// returns 1, 2, 3, 4, 5, or 6
public static int rollDie()
int dieRoll = (int)(Math.random()*6)+1;
return dieRoll;
// Randomly picks number from 1 to 1000.
public static int pickNumber(int 1, int 1000)
int randomNumber = (int)(Math.random());
return randomNumber;
}compile errors:
Gamble.java:32: <identifier> expected
public static int pickNumber(int 1, int 1000)
^
Gamble.java:32: ';' expected
public static int pickNumber(int 1, int 1000)
^
Gamble.java:32: <identifier> expected
public static int pickNumber(int 1, int 1000)
^
Gamble.java:32: illegal start of type
public static int pickNumber(int 1, int 1000)
^
Gamble.java:32: <identifier> expected
public static int pickNumber(int 1, int 1000)
^
Gamble.java:33: ';' expected
^
Gamble.java:35: <identifier> expected
int randomNumber = (int)(Math.random());
^
Gamble.java:37: illegal start of type
return randomNumber;
^
Gamble.java:37: ';' expected
return randomNumber;
^
Gamble.java:41: class, interface, or enum expected
^
10 errors
----jGRASP wedge: exit code for process is 1.
----jGRASP: operation complete.
Thanks in advance!
Wootens
Edited by: Wootens on Oct 4, 2010 5:52 PM
The program is running but its running incorrectly.
Here is the loop. Should there be a specific order in which I should place each if statement? It doesn't seem to be working and I'm not sure how to make it right.
boolean userWon = false; // Haven't one yet.
int guessCount = 0;
while(!userWon) // Keeps going while userWon not true
System.out.println("What is your first guess?");
int userGuess = scan.nextInt();
int computerNumber = Gamble.pickNumber(); // Main calling class method
if(userGuess < computerNumber)
System.out.println("That's too low!.");
else
System.out.println("That's too high!");
if(userGuess == computerNumber)
System.out.println("You got it in " + guessCount+ " guesses! My number was " + computerNumber);
userWon = true;
else if(guessCount==9)
System.out.println("You didn't get the number in 10 guesses.");
System.out.println("You lose. My number was " + computerNumber + ".");
userWon=true;
guessCount++;
}Here is a test run:
----jGRASP exec: java GuessMyNumber
I've picked a secret number
It's between 1 and 1000
You get 10 guesses, try to guess it!
What is your first guess?
500
That's too low!.
What is your first guess?
400
That's too low!.
What is your first guess?
600
That's too low!.
What is your first guess?
800
That's too high!
What is your first guess?
700
That's too high!
What is your first guess?
600
That's too high!
What is your first guess?
500
That's too low!.
What is your first guess?
550
That's too low!.
What is your first guess?
560
That's too high!
What is your first guess?
557
That's too high!
You didn't get the number in 10 guesses.
You lose. My number was 299.
----jGRASP: operation complete.
What should I change around to make it work? :3
Thanks for all the help so far!
Edited by: Wootens on Oct 4, 2010 10:09 PM
Similar Messages
-
Hi,
I'm using Jdev 10.1.3, and my problem is the following one:
In my connection definition, that ORACLE_JDBC_TYPE is oci8 and when i try to conenct to BD, it occurs:
java.lang.UnsatisfiedLinkError: no ocijdbc10 in java.library.path
I've Oracle Client 9i and 8i, i've used each of them, but it doesn'nt work
I've drivers,jar, dll of client 10, becuase i supposse that it is that application need,
and i copy them in jdbc/lib of Oracle client(8i and 9i) and in jDev 10.1.3, but it doesn`t work.
The files are :
jars:: classes12.jar and ojdbc14.jar
dll ::oci.dll,ocijdbc10.dll, ociw32.dll,orannzsbb10.dll,oraocci10.dll and oraociei10.dll
Is there other path else where i should copy this jars,dllls?
Could we help me?
Thanks.I am not familiar with Mac OS, but there are two things I can think of that you can check:
- This is trivial, and you probably did that: ist libocijdbc10.dylib in /usr/local/oracle/instantclient10_1 ?
- Could it be that Java is 32-bit and libocijdbc10.dylib is 64-bit or vice versa?
Yours,
Laurenz Albe -
How can i find what the java.library.path is?? urgent
Hi,
I have an unsatisfiedlinkerror and the message is no jicmp in java.library.path. can anyone tell me how to do System.out.println and the path???
This is very urgent so anyhelp would be gratefully recieved
Thanks
VanessaI have an unsatisfiedlinkerror and the message is no
jicmp in java.library.path.
can anyone tell me how to
do System.out.println and the path???System.getProperty() will retrieve the Java-defined system properties. You can use the following code to determine the available values:
public static void main( String [] args ) {
java.util.Properties p = System.getProperties();
java.util.Enumeration keys = p.keys();
while( keys.hasMoreElements() ) {
System.out.println( keys.nextElement() );
Refer http://www.javaworld.com/javaworld/javaqa/2001-07/01-qa-0706-env.html
Jatin -
Please how i can pass java.library.path switch to JVM during JVM creating in C++...????
Check out this tutorial: http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-12.html
Do a search for the word 'Djava.library.path'
fitz -
How to pass java.library.path as a VM argument in JNLP file
I jave a jar file containing reference to sqljdbc4.jar as I am using JDBC to talk with SQL Server. It works fine through eclipse IDE when I give the fillowing VM Argument
-Djava.library.path=C:\Users\reddys2\Downloads\sqljdbc_4.0\enu\auth\x86. Without this I get the "error message" saying that "failed to load sqljdbc_auth.dll
Now I would like to bundle working jar file in .jnlp and invoke through browser. I tried to add vm argunment (<property name="java.library.path" value="C:\Users\reddys2\Downloads\sqljdbc_4.0\enu\auth\x86"/> ) in the .jnlp file. But still i am getting "WARNING:Failed to load the sqljdbc_auth.dll cause:no sqljdbc_auth in java.library.path"
Any help is greatly appreciated. Here are the contents of JNLP file
=======================================================================================
?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="http://xxx.16.19.56:8080/ifsdTools/" href="PF_UserList.jnlp">
<information>
<title>Login into PF</title>
<vendor>XXX XXXX</vendor>
<description>Provides ability to mirror PF Data base locally</description>
</information>
<resources>
<j2se version="1.4+"/>
<jar href="PopulateIFSDProjectForgeData.jar" />
<jar href="Psqljdbc4.jar" main/>
<property name="java.library.path" value="."/>
<property name="javax.net.ssl.keyStore" value="NONE"/>
<property name="javax.net.ssl.keyStoreType" value="PKCS11"/>
<property name="http.proxyHost" value="proxy1.lmco.com"/>
<property name="http.proxyPort" value="80"/>
<property name="java.library.path" value="C:\Users\xxxx\Downloads\sqljdbc_4.0\enu\auth\x86"/>
<property name="pfProjectId" value="proj1073" />
</resources>
<security>
<all-permissions/>
</security>
<application-desc main-class="ifsdTools.PopulateIFSDProjectForgeData" />
</jnlp>
=========================================================================================================
Edited by: 878645 on Apr 26, 2012 3:43 PMThanks for the pointer. Question that I have is I am referencing sqljdbc4.jar in my application, which in turn using sqljdbc_auth.dll.
Which one should i refernce through <nativelib>. Is it sqljdbc4.jar or sqljdbc_auth.dll.
have added the following line to the .jnlp.
<nativelib href="sqljdbc4.jar"/>
But still it is complaining on sqljdbc_audth.dll. If it is sqljdbc_auth.dll, can I use <nativelib> to pass it.
In that case does it need to be signed?. If so,
Is it possible to sign .dll using 'jarsigner'?.
Edited by: 878645 on Apr 26, 2012 3:43 PM -
Global java-library for graphical mapping?
we hava a global .jar-java library we want to use in all software components (and not import them into all software comonents)
in xi2.0 there was a procedure to update library.txt and reference.txt:
reference library:XILookup library:jco
(The XILookup class needs access to JCO)
reference IntegrationServices library:XILookup
(make XILookup visible to mapping runtime)
reference ExchangeRepository library:XILookup
(make XILookup visible to design-time)
now in xi 3.0 we deployed the library as a j2ee library using nwds
but how can i create the referenze to the exchangerepository and mapping runtime?
thanks for any help
joergHello
I have the same problem. I want deploy also a jar library on xi system and after use this library for a messages mapping.
I won't use the external Archives, i must use the library for different names spaces.
I use for the deploying a library module in the NetWeaver developer studio. The deploying is working. But the mapping never found the jar library.
Thanks for help.
Regards Tom -
How do i print out the java.library.path??
hi, can anyone show me how to print out java.library.path to the terminal? im having unsatisfiedlinkerror problems
thanks for help in advance
vanessaSystem.out.println(System.getProperty("java.library.path"));
-
Incorporating a Java library that depends on JOGL into JavaFX 1.3
I am developing a JavaFX application that has a Java library (specifically World Wind Java) that uses jogl.jar. In JavaFX releases before 1.3, there was no problem in using this Java library. However, in JavaFX 1.3 there are issues. I noticed that JavaFX 1.3 has split jogl.jar into jogl-common.jar and jogl-awt.jar. The Java library has been built and tested with the regular jogl.jar. I can successfully build the application by adding jogl.jar to the JavaFX 1.3 application. But, I can not run the application. I get this runtime error:
java.lang.NoSuchMethodError: com.sun.opengl.impl.Debug.isPropertyDefined(Ljava/lang/String;)Z
at javax.media.opengl.GLJPanel.<clinit>(GLJPanel.java:114)
How do you have jogl.jar and (jogl-awt.jar and jogl-common.jar) coexist in the same JavaFX 1.3 application?
Thanks,
BobbyUpon further research, World Wind Java is using JOGL version 1.1 and JavaFX 1.3 uses JOGL version 2.0. In Netbeans 6.9 beta, a JavaFX project with the World Wind jar file and JOGL 1.1 jar file will build but will not run. Removing the reference to JOGL jars from the JavaFX SDK, specifically jogl-awt.jar and jogl-common.jar, will allow the application to run through netbeans. When running the javafx application through java web start, the jogl 1.1 jar does not conflict with JavaFX's jogl 2.0 jars (for some reason) and the application runs correctly. So problem solved.
Bobby -
Where to Place java library(.jar) in your application
Hi,
I am using ColdFusion - 9 in my application. Also, I am using some third party java library. I put my library in "\ColdFusion9\lib\" but now my library version is changed. So I need to update those files by replacing the old files.
My Question Is: Can we place the java .jar files in some location inside my application directory. So that I don't have to do any changes with the ColdFusion library directory for using those libraries.
ThanksCF10 brings in custom paths for this sort of thing:
http://help.adobe.com/en_US/ColdFusion/10.0/Developing/WSe61e35da8d318518-106e125d1353e804 331-7ffe.html
But this is no help to you. However there's a third-party solution which'll work on CF9:
http://javaloader.riaforge.org/
I've never used it, but I've heard good reports from people who have.
Adam -
Is there any java library like MSDN
is there any java library like MSDN ? probabily you will say java docs .....but java doc dont show any example code.
MSDN gives syntax+example code almost everything.
java docs gives the syntax ....but they dont carry example codes. I have downloaded java docs.
what you people use ? is there any other better thing ?is there any java library which carry example code along with syntax?
plz share your experience
thanksis there any java library like MSDN ? probabily you
will say java docs .....but java doc dont
show any example code.For TONS of examples try here
It also has very detailed explanations with these examples as to why they work (or don't work, if that's the case). -
Java Library to drop the incoming packet flow
hi there,
i m planning to make application layer filter. i need to drop the flow of incoming packets. So can anyone suggest me any java library which is able do this?
or else if i have to create my own library then how can i proceed in that?thnx oscar 4 ur reply...
actually i want to drop the incoming packets which r coming from restricted URL. means any how i want to restrict the user to see the particular webpage.
so if cant hav this low level API in java, then can u suggest me how to implement it in other way?..
i hav to make this project in JAVA only.
i have got one API named "libipq" (source: snort.org) which can drop the packet flow. But this API is for linux OS and i want to implement on windows... pls help -
Oracle Calendar - UnsatisfiedLinkError: no csdkjni in java.library.path
Hi, all.
I deployed my test calendar application developed using Jdeveloper 10.1.3.0 (on Windows XP) to the Oracle 10.1.3. AS on a linux server, but the CalendarServer in on another installation (Collaboration Suite 10.1.2) on the same linux server.
When I try to executed the code that calls the calendar server I get this error:
500 Internal Server Error
javax.faces.el.EvaluationException: java.lang.UnsatisfiedLinkError: no csdkjni in java.library.path
I set the LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib:$ORACLE_HOME/ocal/lib on the collaboration suite 10.1.2 installation.
When I try to run the code on my Jdeveloper I get the same error:
java.lang.UnsatisfiedLinkError: no csdkjni in java.library.path
In my windows machine I create a folder where I put the dll's and jar files that came from the collaboration suite windows installation, but I get always the same error
This is the code:
try
Api.init("calendar.ini", "calendar.log");
catch(Api.StatusException e)
System.out.println("init returned status'" + e.getMessage() + "'");
System.exit (1);
Is my approach correct? Because if i'm developing on Windows and I need dll's files to connect to the calendar server on linux, but when I deploy the application to the linux server those dll's are useless and cannot be used. So am I missing something here? Do I need anything else to get this to work?
Best Regards,
Rui1. Use 1 and only 1 of classes12.zip and ojbc14.jar; they have different versions of the same classes in them.
2. The Oracle OCI driver for JDBC uses .dll files or .so files from the Oracle client installation (as well as Oracle network configuration files, I think); most people use the thin driver instead to avoid this problem.
To use the thin driver, change your url, see here for details:
http://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq.htm#05_00
To stay with the OCI driver (not recommended), you need to have the appropriate Oracle client installation (or at least get the dlls or sos), and I think set additional environment variables, such as ORACLE_HOME and possibly LD_LIBRARY_PATH. I don't do this myself, so I can't give much more advice. -
How to import java library file to forms 6i
Hi all,
Is it possible to import java library file to forms 6i. Please help me.The Java importer is introduced in 9i.
However, most java functionality is added to Forms in the client, not the server. In 6i you can add Java pluggable components to your forms. You need to make a Java Pluggable Component to do this. Stand-alone Java beans can only be called from Forms 9i on using the fbean package.
So it depends on what you want to do with the java whether it is possible to use it in 6i. -
PHP & JAVA (Unable to load Java Library)
Hello,
I try to execute a script ncluding the call with JAVA routines, I obtain the following message:
Fatal error: Unable to load Java Library /opt/j2sdk1.4.2_04/jre/lib/i386/libjava.so, error: libjvm.so: cannot open shared object file: No such file or directory in /usr/local/apache2/htdocs/prerequis.php on line 17
My environment is as follows:
Linux REDHAT 2.4.21, Apache 2.0.50, PHP 4.3.9, JDK 1.4.2_04
Files php.ini :
[Java]
java.class.path = /usr/local/lib/php/php_java.jar
java.home = /opt/j2sdk1.4.2_04
java.library = /opt/j2sdk1.4.2_04/jre/lib/i386/libjava.so
java.library.path = /usr/local/lib/php/extensions/no-debug-non-zts-20020429
extension_dir = /usr/local/lib/php/extensions/no-debug-non-zts-20020429
extension=java.so
If somebody has an idea??
ThanksShouldn't java.library.path point to java.library?
-
No ocijdbc9 in java.library.path
I am running an app against Oracle 8.17 with an OCI connection using ocijdbc8.dll. The web server is Tomcat 3.2.3. The app has no problem connecting to the database.
If I run against Tomcat 4 I get the error
java.lang.UnsatisfiedLinkError: no ocijdbc9 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1312)
at java.lang.Runtime.loadLibrary0(Runtime.java:749)
at java.lang.System.loadLibrary(System.java:820)
at oracle.jdbc.oci8.OCIDBAccess.logon(OCIDBAccess.java:294)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:307)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:442)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:321)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
I do not have Oracle 9i installed so don't know why it is trying to use ocijdbc9.
When I switch back to Tomcat 3 there is no problem.
The Classpath has the Classes12.zip for Oracle 8.1.7
Can anybody shed any light on this??What is the platform this product is running on? Is LD_LIBRARY_PATH (through wrapper.env) or java.library.path set in jserv.properties?
-
Java.lang.UnsatisfiedLinkError: no ocijdbc8 in java.library.path
hi,
i am trying to connect to an oracle 8.1.7 database from my application running on tomcat 4.0.3 / jdk1.4 /windows nt.
using the thin jdbc-driver (classes12.zip) everything works fine.
when i try using the oci8-driver, i get an error-message saying:
java.lang.UnsatisfiedLinkError: no ocijdbc8 in java.library.path
i have the oracle-client installed on my machine.
the ocijdbc8.dll can be found in D:\server\oracla81\bin
the environment-variables PATH, CLASSPATH, LD_LIBRARY_PATH (i'm not sure if this has any meaning on nt) all point to this directory.
i start tomcat using the following option: -Djava.library.path="D:\server\oracla81\bin"
my application can see this variable:
System.out.println("java.library.path: "+System.getProperty("java.library.path"));
prints out the correct value.
then i try to load the library by myself:
try {
System.loadLibrary("ocijdbc8");
System.out.println("Successfully Loaded");
} catch(Exception e) {
System.out.println("LD_LIBRARY_PATH is not properly set");
e.printStackTrace();
everything works fine! the library is loaded!
finally i try to connect to the database and the application throws the mentioned exception:
lang.UnsatisfiedLinkError: no ocijdbc8 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1410)
at java.lang.Runtime.loadLibrary0(Runtime.java:772)
at java.lang.System.loadLibrary(System.java:832)
at oracle.jdbc.oci8.OCIDBAccess.logon(OCIDBAccess.java:228)
at oracle.jdbc.driver.OracleConnection.(OracleConnection.java:249)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:365)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:260)
any help would be appreciated.
thanx in advance,
frank.
[email protected]It is probably JDK 1.4 that causes the problem. I was able to get strange errors with that version of the JDK with code that worked fine using 1.31.
Maybe you are looking for
-
HT1212 my daughter disabled my iphone - how can I get it to work again?
my daughter diabled my phone - how can i get it to work again?
-
Re: EOS 5D Mark II fails to connect (Code 43) but 5D Mark III connects fine!
Hi Mike, I'm new to this forum and this is my first post. I had looked for the Delete Post option but couldn't locate it. Here's a quick update. I later discovered the one pin on each of the 5D Mark II port was bent, using a VisibleDust sensor loupe.
-
How do I launch upgrade wizard in 8.8
Hi, I am trying to upgrade a B1 2007 db to B1 8.8. I know that i need to run the upgrade wizard to perform the upgrade but have no clude how/where to find it. I have checked the 8.8 cd and coiuld not find any installed. Also checked server tools
-
Unknown error occurs [-20] when trying to sync purchased songs to ipod
I have purchased 5 songs via itunes store, and they will no sync to my ipod. an 'unknown error [-20]' occurs then, 'and error occurred while writing the devide' then 'the ipod cannot be synced'. please help!
-
Question about stopping an flv file
I have created a .flv file from a wmv file using Flash Video Encoder CS3. I didn't see a way in the encoder settings nor in Dreamweaver CS3 to stop the video on the last frame. How could I accomplish that? Thanks, David