________________ ZooFileWriter.java _____________________
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class ZooFileWriter {
public static String padLeft(String str, int leng,String stringpadVal) {
for (int i = str.length(); i <= leng; i++)
str = stringpadVal + str;
return str;
}
public static String padRight(String str, int leng,String stringpadVal) {
for (int i = str.length(); i <= leng; i++)
str = str + stringpadVal;
return str;
}
public static void createZooFile() {
try{
String entermore= “Y”;
FileWriter fw=new FileWriter(“zoodata.txt”);
BufferedReader reader =
new BufferedReader(newInputStreamReader(System.in));
StringanimalName,trackNumber,animalType,animalSubType,eggs,Nurse;
do
{
System.out.println(“Track Number:”);
trackNumber =reader.readLine();
trackNumber = padLeft(trackNumber,6,”0″);
System.out.println(“Enter AnimalName: “);
animalName =reader.readLine();
animalName = padRight(animalName,15,” “);
System.out.println(“Enter AnimalType: “);
animalType =reader.readLine();
animalType = padRight(animalType,15,” “);
System.out.println(“Enter AnimalSub-type: “);
animalSubType =reader.readLine();
animalSubType =padRight(animalSubType, 15,” “);
System.out.println(“Enter Number ofEggs: “);
eggs =reader.readLine();
System.out.println(“Enter 1 ifNursing, 0 if not: “);
Nurse =reader.readLine();
fw.write(trackNumber+””+animalName+” “+animalType+” “+animalSubType+” “+eggs+” “+Nurse);
System.out.println(“Enter moredata? (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 successfullycreated…”);
}
}
_______________ TheZoo.cpp _______________________
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 invocationoptions
options[0].optionString = (char*) “-Djava.class.path=”; // where tofind 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 JVMinit 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 initialisationoptions.
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 findthe 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 (orarray)
*/
}
void RemoveAnimal()
{
/*
TODO: Write proper code to remove an animal from your vector (orarray. Remmber to re-allocate proper size if using array)
*/
}
void LoadDataFromFile()
{
/*
TODO: Write proper code to load data from input file (generatedusing 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 selectfrom
*/
}
int main()
{
GenerateData();
return 1;
}
W WW. Wildlife Zoo CS 210 Wildlife Zoo Interface Guide Functional Requirements 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 Eggs: Integer vi. Nurse: Integer V. 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 O 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. WWW Wildlife Zoo Eggs Nurse 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 Crocodile Bat Whale Whale Goose Goose Pelican Pelican Sealion SeaLion Bat 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. Animal + name: string Track Num. Integer Oviparous Mammal + NumberOfEERS + Nurse Crocodile Goose Pelican Whale SeaLion d. The message “Load complete.” will display after the data loads successfully. 4. Display Animal Data: Display data on the user’s computer screen in tabular format (presented in the form of a table with rows and columns). W WW. Wildlife Zoo 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. WALD Wildlife Zoo Setting Up JNI Note: If you are not getting any errors on the #include jni.h line, you do not need to follow these steps. To be able to properly link your C++ code to java, you need to load the Java Virtual Machine module. To do this, at the top of the code, type #include <jni.h>. At first, this will give you an error because Eclipse cannot “see” jni.h. You will fix this in the next step. Fik Ed Source Real Navige Search Prejat Run Target Window Hely SO R P sit 9.4 New Connection. MMOR . 2.6. Quick Acce s ACCProjaca Comedor – Halo World.csp 110 Panclude <ios Teladan 13 int main) 14 GODT !!! Hello World!!!” endl; // DINE !! Hello world!!! To get Eclipse to “see” jni.h, you need to build the path. In the Project Explorer window, right-click your C++ project, and select Properties. New Ge Into cpp Hello.cpp Open in New Window de <iostream dena.h namespace std; E CC !!! Hello world! turn 0; Index Build Configurations Build Targets Build Project Clean Project Remove from Context Copy Paste Delete Move… Ctrl+Alt+Shift+Down X Import Export Tasis Console P Refresh Close Project Run As Debug As Profile As Validate Restore from Local History… Run C/C++ Code Analysis Team Compare With Configure Hello Worl Properties Alt+Enter WAW Wildlife Zoo From the menu pane on the left, select C/C++ Build, then Environment. Under C/C++ builder, click on Environment. In the window, you will see the Environment pane, in the box “Environment variables to set”, double-click on the word PATH. Properties for Hello World typer Erinnen Configuratore Dhag til Masa Gori . Hd Wald C Progames BULD SYSTEM . ULD SYSTEM BULD SYSTEM . FULD SYSTEM MOYS HOME SIM NGW HONE Hallo Waste double-click Arendals to wie weer Replace with speared one Tere Date y Ok Corel In the Edit variable dialog box, look at the box that says Value. There will already be some text in there. Click on the box and use your cursor to scroll to the very end of the text. Then type the following, including the semi-colon;C:Program Files (x86)Javajdk1.8.0_212.Then click OK. NOTE: You cannot copy straight from this Word file on your computer into Eclipse, which is in Apporto. Instead, upload this Word document into Apporto. Then you will be able to copy the code into Eclipse. Properties for Hello World Environment type filter text Resource Builders C/C++ Build Build Variables Environment Logging Configuration: Debug Active] Manage Configurations… Environment variables to set Add… Setting Tool CH Edit variable Edit variable Select… XL C/C Name PATH > C/C++ Ger Edit… Project Ref Value Desktop: C:Program Files (x86)avajdk1.8.0_212 Variables Delete IN OK Cancel Undefine Run/Debu Task Repos Task Tags > Validation WikiText WAW Wildlife Zoo In the menu pane, click on Settings, which is also under C/C++ Build. In the Settings pane, select General under GCC Assembler. Click the Add… icon Properties for Hello World Settings Configuration: Debug (Active] Manage Configurations… A Tool Settings Build Steps P Build Artifact Binary Parsers Error Parsers type filter text > Resource Builders C/C++ Build Build Variables Environment Logging Settings Tool Chain Editor XL C/C++ Compiler C/C++ General Project References Run/Debug Settings > Task Repository Task Tags > Validation Wiki Text Assembler flags Include paths (-1) GCC Assembler General 2 GCC C++ Compiler Dialect Preprocessor Includes 9 Optimization 19 Debugging Warnings Miscellaneous GCC C Compiler Dialect Preprocessor The Add directory path dialog box will pop up. You will need to add the following paths, one at a time. Type in each path and then click “OK.” C:Program Files (x86)avajdk1.8.0_212include C:Program Files (x86)avajdk1.8.0_212includewin32 C:Program Files (x86)avajdk1.8.0_212bin C:Program Files (x86)ava Add directory path Directory CA Program Files(x86) Java’ jdk1.8.0_212.include ok Cancel Workspace. Filesystem. WWW Wildlife Zoo When you are finished, you should see all four paths in the window: Settings Configuration: Debug [ Active] Manage Configurations… Tool Settings Build Steps Build Artifact Binary Parsers Error Parsers 9 GCC Assembler General GCC C++ Compiler Dialect Preprocessor Includes Optimization Assembler flags Include paths (-1) C:Program Files (x86) Uavaljdk1.8.0_212include C:Program Files (x86) Vavajdk1.8.0_212include win32″ C:Program Files (x86) Uavaljdk1.8.0_212bin “C:Program Files (x86) Java” Next, in the Settings pane, select Includes, which is located under the GCC C++ Compiler. Then select the Add… button. Add the following paths the same way you added paths before. C:Program Files (x86)avajdk1.8.0_212include C:Program Files (x86)Javajdk1.8.0_212includewin32 Settings Configuration: Debug Active] Manage Configurations… Tool Settings Build Steps Build Artifact Binary Parsers Error Parsers Include paths (-1) “C:Program Files (x86) Vavaljdk1.8.0_212include” “C:Program Files (x86) Uavajdk1.8.0_212includewin32” GCC Assembler General GCC C++ Compiler Dialect Preprocessor Includes Optimization WAW Wildlife Zoo Finally, under MinGWC++ Linker, click Libraries. You will see two windows. The first is Libraries. Use the “Add…” button to add ivm. In the Library search path (-4) add the following path: C:Program Files (x86)avajdk1.8.0_212lib Settings Configuration Debug Active] Manage Configurations Tool Settings Bulld Steps Build Artifact Binary Paises Error Passers GCC Assemble Librenes (-0 89 GCC C++ Compiler Dialect Preproces 19 Includes Optimization Debugging 19 Warnings Miscellaneous 3 GCC Compiler Chalect Preprocessor Includes Optimization Debugging Warnings Miscellaneous 29 Mind Liner Libraries Miscelaneous Share Library Settings Finally, click the “OK” button to close the windows. You may see a screen that prompts you to rebuild the libraries, click OK. When this is completed, you will be taken back to the Eclipse homescreen, and you should see that the #include <jni.h> error is now gone! C/C++. Hello world/src/Hello World.cpp – Eclipse File Edit Source Refactor Navigate Search Project Run Target Window Help SO O Run Paint1 V D -RO – New Connection. MM O C/C++ Projects Connections Hello World.cpp Hello.cpp! > Hello World 9 Winolude <iostream> 10 include <ni.h> in pace std; 13 int main() { cout << “!!! Hello world!!!” << endl; // prints !!! Hello world!!! return 0; WWW Wildlife Zoo UML Class Diagram Text Version In this text version, each class is created as a table with the class name as a header. There are arrows demonstrating inheritance connecting the different tables, each with alt-text descriptions. The UML class diagram displays a total of nine classes. The abstract class is Animal, which has two variables: a String variable called “name” and an Integer called “code”. Inheriting from that class are two classes: Oviparous, which has a variable +NumberofEggs, and Mammal, which has a variable +Nurse. There are three classes which inherit from Oviparous: Crocodile, Goose, and Pelican. There are three classes which inherit from Mammal: Bat, Whale, and Sealion. Animal – name : String – code: Integer (no methods listed) Oviparous +NumberofEggs Mammal +Nurse Crocodile Goose Pelican Whale Sealion Show transcribed image text W WW. Wildlife Zoo CS 210 Wildlife Zoo Interface Guide Functional Requirements 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 Eggs: Integer vi. Nurse: Integer V. 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 O 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.
WWW Wildlife Zoo Eggs Nurse 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 Crocodile Bat Whale Whale Goose Goose Pelican Pelican Sealion SeaLion Bat 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. Animal + name: string Track Num. Integer Oviparous Mammal + NumberOfEERS + Nurse Crocodile Goose Pelican Whale SeaLion d. The message “Load complete.” will display after the data loads successfully. 4. Display Animal Data: Display data on the user’s computer screen in tabular format (presented in the form of a table with rows and columns).
W WW. Wildlife Zoo 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.
WALD Wildlife Zoo Setting Up JNI Note: If you are not getting any errors on the #include jni.h line, you do not need to follow these steps. To be able to properly link your C++ code to java, you need to load the Java Virtual Machine module. To do this, at the top of the code, type #include . At first, this will give you an error because Eclipse cannot “see” jni.h. You will fix this in the next step. Fik Ed Source Real Navige Search Prejat Run Target Window Hely SO R P sit 9.4 New Connection. MMOR . 2.6. Quick Acce s ACCProjaca Comedor – Halo World.csp 110 Panclude Validation WikiText
WAW Wildlife Zoo In the menu pane, click on Settings, which is also under C/C++ Build. In the Settings pane, select General under GCC Assembler. Click the Add… icon Properties for Hello World Settings Configuration: Debug (Active] Manage Configurations… A Tool Settings Build Steps P Build Artifact Binary Parsers Error Parsers type filter text > Resource Builders C/C++ Build Build Variables Environment Logging Settings Tool Chain Editor XL C/C++ Compiler C/C++ General Project References Run/Debug Settings > Task Repository Task Tags > Validation Wiki Text Assembler flags Include paths (-1) GCC Assembler General 2 GCC C++ Compiler Dialect Preprocessor Includes 9 Optimization 19 Debugging Warnings Miscellaneous GCC C Compiler Dialect Preprocessor The Add directory path dialog box will pop up. You will need to add the following paths, one at a time. Type in each path and then click “OK.” C:Program Files (x86)avajdk1.8.0_212include C:Program Files (x86)avajdk1.8.0_212includewin32 C:Program Files (x86)avajdk1.8.0_212bin C:Program Files (x86)ava Add directory path Directory CA Program Files(x86) Java’ jdk1.8.0_212.include ok Cancel Workspace. Filesystem.
WWW Wildlife Zoo When you are finished, you should see all four paths in the window: Settings Configuration: Debug [ Active] Manage Configurations… Tool Settings Build Steps Build Artifact Binary Parsers Error Parsers 9 GCC Assembler General GCC C++ Compiler Dialect Preprocessor Includes Optimization Assembler flags Include paths (-1) C:Program Files (x86) Uavaljdk1.8.0_212include C:Program Files (x86) Vavajdk1.8.0_212include win32″ C:Program Files (x86) Uavaljdk1.8.0_212bin “C:Program Files (x86) Java” Next, in the Settings pane, select Includes, which is located under the GCC C++ Compiler. Then select the Add… button. Add the following paths the same way you added paths before. C:Program Files (x86)avajdk1.8.0_212include C:Program Files (x86)Javajdk1.8.0_212includewin32 Settings Configuration: Debug Active] Manage Configurations… Tool Settings Build Steps Build Artifact Binary Parsers Error Parsers Include paths (-1) “C:Program Files (x86) Vavaljdk1.8.0_212include” “C:Program Files (x86) Uavajdk1.8.0_212includewin32” GCC Assembler General GCC C++ Compiler Dialect Preprocessor Includes Optimization
WAW Wildlife Zoo Finally, under MinGWC++ Linker, click Libraries. You will see two windows. The first is Libraries. Use the “Add…” button to add ivm. In the Library search path (-4) add the following path: C:Program Files (x86)avajdk1.8.0_212lib Settings Configuration Debug Active] Manage Configurations Tool Settings Bulld Steps Build Artifact Binary Paises Error Passers GCC Assemble Librenes (-0 89 GCC C++ Compiler Dialect Preproces 19 Includes Optimization Debugging 19 Warnings Miscellaneous 3 GCC Compiler Chalect Preprocessor Includes Optimization Debugging Warnings Miscellaneous 29 Mind Liner Libraries Miscelaneous Share Library Settings Finally, click the “OK” button to close the windows. You may see a screen that prompts you to rebuild the libraries, click OK. When this is completed, you will be taken back to the Eclipse homescreen, and you should see that the #include error is now gone! C/C++. Hello world/src/Hello World.cpp – Eclipse File Edit Source Refactor Navigate Search Project Run Target Window Help SO O Run Paint1 V D -RO – New Connection. MM O C/C++ Projects Connections Hello World.cpp Hello.cpp! > Hello World 9 Winolude 10 include in pace std; 13 int main() { cout
Expert Answer
Answer to ________________ ZooFileWriter.java _____________________ import java.io.FileWriter; import java.io.BufferedReader; imp…