NMI with arguments


// prompts for user's birth year
// and returns his/her fortune for the day

import java.lang.*;

class Iching1 {

    private native String getfortune(int i, String s);

    static {
        System.loadLibrary("iching1");
    }

    public static void main(String args[]) {
        Iching1 ich = new Iching1();
        int seed= (int) (10*Math.random());
        String fortune = ich.getfortune(seed,"Please enter your birth year.");
        System.out.println("Your today's fortune is...\n\n" + fortune + "\n\n");
    }

}
 
 


 
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Iching1 */

#ifndef _Included_Iching1
#define _Included_Iching1
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     Iching1
 * Method:    getfortune
 * Signature: (ILjava/lang/String;)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_Iching1_getfortune
  (JNIEnv *, jobject, jint, jstring);

#ifdef __cplusplus
}
#endif
#endif
 
 

 


  #include "Iching1.h"
#include <stdio.h>

JNIEXPORT jstring JNICALL Java_Iching1_getfortune
    (JNIEnv *env, jobject obj, jint i, jstring s) {

    char buf[128];
    int byr, predict;
    char fortune[10][200]=
        { "Plain dealing will keep you out of trouble.",
          "The situation is about to change for the better.",
          "Pay attention to small warnings.  Hard times lie ahead.",
          "Don't keep hitting your head against a stone wall.\nChannel your energy to attainable goals.",
          "Overconfidence will lead to misadventure and regret.",
          "For the moment, you are free of worry.",
          "Do what you have to do, but if it ain't broken, don't fix it.",
          "Honors, wealth, health and long life are in store as problems disappear.",
          "Accept defeat and repent.  You will become at peace with yourself.",
          "Never give up.  Good times lie ahead." };

    /* Obtain a C-copy of the Java string */
    const char *str = (*env)->GetStringUTFChars(env, s, 0);

    /* Display input prompt */
    printf("\n\n%s\n", str);

    /* Release string buffer */
    (*env)->ReleaseStringUTFChars(env, s, str);

    /* Process user and method argument input (jint i) to select today's fortune  */
    scanf("%s", buf);
    byr= atoi(buf);
    predict= (byr*i)%10;

    /* Return today's fortune to the invoking object */
    return (*env)->NewStringUTF(env, fortune[predict]);

}
 
 
 



  #include "Iching1.h"
#include <stdio.h>
#include <stdlib.h>

extern "C" /* specify the C calling convention */

JNIEXPORT jstring JNICALL Java_Iching1_getfortune
  (JNIEnv *env, jobject obj, jint i, jstring s) {

    char buf[128];
    int byr, predict;
    char fortune[10][200]=
        { "Plain dealing will keep you out of trouble.",
          "The situation is about to change for the better.",
          "Pay attention to small warnings.  Hard times lie ahead.",
          "Don't keep hitting your head against a stone wall.\nChannel your energy to attainable goals.",
          "Overconfidence will lead to misadventure and regret.",
          "For the moment, you are free of worry.",
          "Do what you have to do, but if it ain't broken, don't fix it.",
          "Honors, wealth, health and long life are in store as problems disappear.",
          "Accept defeat and repent.  You will become at peace with yourself.",
          "Never give up.  Good times lie ahead." };

    /* Obtain a C-copy of the Java string */
    const char *str = env->GetStringUTFChars(s, 0);

    /* Display input prompt */
    printf("\n\n%s\n", str);

    /* Release string buffer */
    env->ReleaseStringUTFChars(s, str);

    /* Process user and method argument input (jint i) to select today's fortune  */
    scanf("%s", buf);
    byr= atoi(buf);
    predict= (byr*i)%10;

    /* Return today's fortune to the invoking object */
    return env->NewStringUTF(fortune[predict]);

}
 
 
 



 
 

//-------------------------------------------
// filename: Iching2.java
//-------------------------------------------
// prompts for user's birth year
// and returns his/her fortune for the day

import java.lang.*;

class Iching2 {

  String msgs[] = new String[] {
    "Plain dealing will keep you out of trouble.",
    "The situation is about to change for the better.",
    "Pay attention to small warnings.  Hard times lie ahead.",
    "Don't keep hitting your head against a stone wall.\nChannel your energy to attainable goals.",
    "Overconfidence will lead to misadventure and regret.",
    "For the moment, you are free of worry.",
    "Do what you have to do, but if it ain't broken, don't fix it.",
    "Honors, wealth, health and long life are in store as problems disappear.",
    "Accept defeat and repent.  You will become at peace with yourself.",
    "Never give up.  Good times lie ahead." };

  private native String getfortune(int i, String s, String[] ss);

  static {
    System.loadLibrary("iching2");
  }

  public static void main(String args[]) {
    Iching2 ich = new Iching2();
    int seed= (int) (10*Math.random());
    String fortune = ich.getfortune(seed,"Please enter your birth year.",ich.msgs);
    System.out.println("\n...Your today's fortune is...\n\n" + fortune + "\n\n");
  }

}
 
 
 

//---------------------------------
// filename:  Iching2.h
//---------------------------------

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Iching2 */

#ifndef _Included_Iching2
#define _Included_Iching2
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     Iching2
 * Method:    getfortune
 * Signature: (ILjava/lang/String;[Ljava/lang/String;)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_Iching2_getfortune
  (JNIEnv *, jobject, jint, jstring, jobjectArray);

#ifdef __cplusplus
}
#endif
#endif
 
 
 

//---------------------------------
// filename:  Ich2.cc
//---------------------------------

#include "Iching2.h"
#include <stdio.h>
#include <stdlib.h>

extern "C" /* specify the C calling convention */

JNIEXPORT jstring JNICALL Java_Iching2_getfortune
  (JNIEnv *env, jobject obj, jint i, jstring s, jobjectArray ss) {

    char buf[128];
    int byr, predict;

    /* Obtain a C-copy of the Java string */
    const char *str = env->GetStringUTFChars(s, 0);

    /* Display input prompt */
    printf("\n\n%s\n", str);

    /* Release string buffer */
    env->ReleaseStringUTFChars(s, str);

    /* Process user and method argument input (jint i) to select today's fortune  */
    scanf("%s", buf);
    byr= atoi(buf);
    predict= (byr*i)%10;

    /* Return today's fortune to the invoking object */
    return (jstring) env->GetObjectArrayElement(ss,predict);

}