C++ / Java Wildlife Zoo Interface Assignment

You will write a multiclass C++ interfacing prototype system for Wildlife Zoo that incorporates Java for certain functionalities. Note: The Java file does not need to be modified. It is being attached for reference. Please see the bolded “TODO” in the C++ code below screenshots.
1. A user menu which displays the following options:
2. Load Animal Data
3. Generate Data
4. Display Animal Data
5. Add Record
6. Delete Record
7. Save Animal Data
8. Generate Data: Your supervisor has created this code for you in Java. In the C++ class you have been given, the createZooFile() function has been created for you. You should not modify the Java code.
9. a. For this function, you should make sure the user menu calls the createZooFile() function when the user selects Generate Data from the menu.
10. b. You will need to call this function and generate a file. When you are prompted for input, remember the following character limits:
11. i. Track #: 6 characters
12. ii. Name: 15 characters
13. iii. Type: 15 characters
14. iv. Sub-type: 15 characters
15. v. Eggs: Integer
16. vi. Nurse: Integer
17. Load Animal Data:
18. a. In your zipped folders, you have been given a Java class that generates a fixed length file. It will prompt the user to enter data for the following fields:
19. Track #: Received from the RFID chip technology
20. Name: Name given to the animal
21. Type: Oviparous (egg laying) or Mammal (primarily non-egg laying)
22. Sub-type: Crocodile, Bat, Whale, and so on
23. Eggs: Number of eggs laid
24. Nurse: Should read 0 if the animal is not nursing, 1 if it is
25. b. Data in the file will look like this. Column widths in the actual file will be fixed and are respectively 6 characters, 15 characters, 15 characters, 15 characters, and two integer columns.
c. You must give users the ability to load this data into memory via a vector within your system. Use the following UML class diagram to build your class hierarchy and inheritance. Notice the variables listed in the Animal, Oviparous, and Mammal classes. A text version is available on the last page of this document.
d. The message Load complete. will display after the data loads successfully.
4. Display Animal Data: Display data on the users computer screen in tabular format (presented in the form of a table with rows and columns).
5. Add Record: Provide the capability to add new animal records.
6. a. When this menu option is selected, the application should prompt the user to enter values for the variables Track#, Name, Type, Sub-type, Eggs, and Nurse.
7. i. Make sure to validate input.
8. b. The user should have the ability to save or cancel the addition.
9. Delete Record: Provide the capability to delete animal records.
10. a. Delete an animal record by Track# when the user selects the Delete Record option from the menu.
11. i. Make sure to validate input.
12. b. The user should be prompted to confirm the deletion before the record is removed from the system.
13. c. The message Animal successfully deleted should display once the operation finishes.
14. Save Data: Permit the user to save modified animal data back to the input file, erasing the data that was previously there. The message Save successfully completed should display once finished.
C++ File:
#include <iostream>
#include <jni.h>
using namespace std;
void GenerateData() //DO NOT TOUCH CODE IN THIS METHOD
{
JavaVM jvm; // Pointer to the JVM (Java Virtual Machine)JNIEnv env; // Pointer to native interface
//================== prepare loading of Java VM ============================
JavaVMInitArgs vm_args; // Initialization arguments
JavaVMOption options = new JavaVMOption[1]; // JVM invocation optionsoptions[0].optionString = (char) “-Djava.class.path=”; // where to find java .class
vm_args.version = JNI_VERSION_1_6; // minimum Java version
vm_args.nOptions = 1; // number of options
vm_args.options = options;
vm_args.ignoreUnrecognized = false; // invalid options make the JVM init fail
//=============== load and initialize Java VM and JNI interface =============
jint rc = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args); // YES !!
delete options; // we then no longer need the initialisation options.
if (rc != JNI_OK) {
// TO DO: error processing…
cin.get();
exit(EXIT_FAILURE);
}
//=============== Display JVM version =======================================
cout << “JVM load succeeded: Version “;
jint ver = env->GetVersion();
cout << ((ver >> 16) & 0x0f) << “.” << (ver & 0x0f) << endl;
jclass cls2 = env->FindClass(“ZooFileWriter”);  // try to find the class
if (cls2 == nullptr) {
        cerr << “ERROR: class not found !”;
}
else {                                  // if class found, continue
        cout << “Class MyTest found” << endl;
        jmethodID mid = env->GetStaticMethodID(cls2, “createZooFile”, “()V”);  // find method
        if (mid == nullptr)
              cerr << “ERROR: method void createZooFile() not found !” << endl;
        else {
              env->CallStaticVoidMethod(cls2, mid);                      // call method
              cout << endl;
        }
}

jvm->DestroyJavaVM();
cin.get();
}
void AddAnimal()
{
/*

        **TODO: Write proper code to add an animal to your vector (or array)**

*/
}
void RemoveAnimal()
{
/*

        **TODO: Write proper code to remove an animal from your vector (or array. Remmber to re-allocate proper size if using array)**

*/
}
void LoadDataFromFile()
{
/*

        **TODO: Write proper code to load data from input file (generated using JNI) into vector/array.**

*/
}
void SaveDataToFile()
{
/*

        **TODO: Write proper code to store vector/array to file.**

*/
}
void DisplayMenu()
{
/*

        **TODO: write proper code to display menu to user to select from**

*/
}
int main()
{
    GenerateData();

    return 1;
}
Java function that needs to be called: only for reference.
public static void createZooFile() {
                          try{

                                       

                                        String entermore = “Y”;

                                       

                      FileWriter fw=new FileWriter(“zoodata.txt”); 

                      BufferedReader reader =

                              new BufferedReader(new InputStreamReader(System.in));

                      String animalName,trackNumber,animalType,animalSubType,eggs,Nurse;

     

                      do

                      {

                                    System.out.println(“Track Number: “);

                                    trackNumber = reader.readLine();

                                    trackNumber = padLeft(trackNumber, 6,”0″);

                       

                                   

                                    System.out.println(“Enter Animal Name: “);

                                    animalName = reader.readLine();

                                    animalName = padRight(animalName, 15,” “);

                                    System.out.println(“Enter Animal Type: “);

                                    animalType = reader.readLine();

                                    animalType = padRight(animalType, 15,” “);

                                    System.out.println(“Enter Animal Sub-type: “);

                                    animalSubType = reader.readLine();

                                    animalSubType = padRight(animalSubType, 15,” “);

                                    System.out.println(“Enter Number of Eggs: “);

                                    eggs = reader.readLine();           

                                    System.out.println(“Enter 1 if Nursing, 0 if not: “);

                                    Nurse = reader.readLine();                       

                                   

                                    fw.write(trackNumber+” “+animalName+” “+animalType+” “+animalSubType+” “+eggs+” “+Nurse); 

                                   

                                    System.out.println(“Enter more data? (Y for yes)”);

                                  entermore = reader.readLine();

                      }

                      while (entermore == “Y”);

                      fw.close(); 

                    }catch(Exception e){System.out.println(e);} 

                    System.out.println(“The file has been successfully created…”); 

          }
}

The specifications for the project are detailed above. The Java code file needs to be called in the .cpp file but needs to remain unaltered. The TODO sections are what I’d like to focus on.  I’m using Eclipse neon.3 IDE for the build.  I also need to create a simple user interface.  The specs are as follows:

Wildlife Zoo Interface Guide
You will write a multi-class C++ interfacing prototype system for the Wildlife Zoo that incorporates Java for certain functionalities. The functional requirements for all components of the interface are as follows.
1. A user menu which displays the following options:
Load Animal Data
Generate Data
Display Animal Data
Add Record
Delete Record
Save Animal Data
2. Generate Data: Your supervisor has created this code for you in Java. In the C++ class you have been given, the createZooFile() function has been created for you. You should not modify the Java code.
a. For this function, you should make sure the user menu calls the createZooFile() function when the user selects Generate Data from the menu.
b. You will need to call this function and generate a file. When you are prompted for input, remember the following character limits:
i. Track #: 6 characters ii. Name: 15 characters
iii. Type: 15 characters
iv. Sub-type: 15 characters
v. Eggs: Integer vi. Nurse: Integer
3. Load Animal Data:
a. In your zipped folders, you have been given a Java class that generates a fixed length
file. It will prompt the user to enter data for the following fields:
Track #: Received from the RFID chip technology
Name: Name given to the animal
Type: Oviparous (egg laying) or Mammal (primarily non-egg laying)
Sub-type: Crocodile, Bat, Whale, and so on
Eggs: Number of eggs laid
Nurse: Should read 0 if the animal is not nursing, 1 if it is
b. Data in the file will look like this. Column widths in the actual file will be fixed and are
respectively 6 characters, 15 characters, 15 characters, 15 characters, and two integer columns.
1
    Track #
000001
000002
000003
000004
000005
000006
000007
000008
000009
000010
000011
Name
Tick-Tock Fidget Willy Bailey Goose Lee Honker Becky Nigel Fluke Rudder Bartok
Type
Oviparous Mammal Mammal Mammal Oviparous Oviparous Oviparous Oviparous Mammal Mammal Mammal
Sub-type Eggs    Nurse
Crocodile 2        0 Bat 0 1 Whale 0        0 Whale 0 1 Goose 0        0 Goose 1 0 Pelican 1        0 Pelican 0 0 SeaLion 0        0
                                        SeaLion Bat
0 1 0        1
        c. You must give users the ability to load this data into memory via a vector within your system. Use the following UML class diagram to build your class hierarchy and inheritance. Notice the variables listed in the Animal, Oviparous, and Mammal classes. A text version is available on the last page of this document.
d. The message Load complete. will display after the data loads successfully.
4. Display Animal Data: Display data on the users computer screen in tabular format (presented in the form of a table with rows and columns).
2

5. Add Record: Provide the capability to add new animal records.
a. When this menu option is selected, the application should prompt the user to enter
values for the variables Track#, Name, Type, Sub-type, Eggs, and Nurse. i. Make sure to validate input.
b. The user should have the ability to save or cancel the addition.
6. Delete Record: Provide the capability to delete animal records.
a. Delete an animal record by Track# when the user selects the Delete Record option
from the menu.
i. Make sure to validate input.
b. The user should be prompted to confirm the deletion before the record is removed from the system.
c. The message Animal successfully deleted should display once the operation finishes.
7. Save Data: Permit the user to save modified animal data back to the input file, erasing the data that was previously there. The message Save successfully completed should display once finished.

You can leave a response, or trackback from your own site.