Question
Can some convert this c++ code to Java for me??? // Call needed functions # include # include # include # include # include using
Can some convert this c++ code to Java for me???
// Call needed functions # include
using namespace std;
// Main function int main() { // Declare variables map
// Ask user for text file names and open text files data.open("data.txt"); name_cities.open("personnel_addresses2.txt"); name_salaries.open("personnel_salaries2.txt");
// Ask for user input and store in variable cout << "Please enter a city name or a partial city name:" << endl; cin >> user_input; // While loop to read through text file containing names and cities, name_cities. // Stores string in line while (getline(name_cities, NameCity)) { // Store just the city in string city, ignore name // That way when the program searches the file it will not match // with any names and just check for matches in the cities city = (NameCity.substr(NameCity.find("|") + 1, NameCity.back()));
// If statement to find if user input is in city if (city.find(user_input) != std::string::npos) { // Store name only in variable name name = NameCity.substr(0, NameCity.find("|")); // Insert name into vector name_vector.push_back(name); } }
// While loop to read through second text file containing names and salaries, salaries // Stores string in sal while (getline(name_salaries, sal)) { // Store name in variable person person = sal.substr(0, sal.find("|")); // Store salary in variable income income = (sal.substr(sal.find("|") + 1, sal.back())); // Insert both values into a map, entire file should be inserted into map NamSalMap[person] = income; }
// For loop to iterate through vector that contains the names of the people that lived in the cities that matched the user input for (vector
// Close all three files data.close(); name_cities.close(); name_salaries.close();
// End program return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started