Help needed! I can\'t figure out what to do. Please be very clear. Thanks for yo
ID: 3794962 • Letter: H
Question
Help needed! I can't figure out what to do. Please be very clear. Thanks for your time.
218/2017 Project 2 Submit Assignment Project 2 Submitting a file upload File Types zip, tgz, gz, and tar.gz Due Mar 3 by 11:55pm Points 100 Available after Feb 8 at 11:55pm Project 2 In this project we are going to be expanding the into the rest of the ways to structure our programs. We will be focusing on loops and functions in addition to selection statements. So you'll be required to use loops and functions in this project. Details For this project we'll be reading in a delimited file. The file will be information about a countries around the globe. Then we'll be processing a series of commands about the file. On each command you'll be reading the file that was given by the command file. You won't be storing the file information in any sort of structure between commands, i.e. no using arrays, vectors, lists, etc. Commands There will be 3 commands we will be dealing with. One of the commands will have 3 versions, so we'll have a total of 5 commands if you want to count them that way. The command file will start with a line that has the word Data File: and then a ile name. That file name is the name of the data file you'll be using for the commands to do its searching. You are not to read and store that information in any sort of array, list, vector, etc size the size command will have one of 3 subcommands after it average if the word average comes after the size command, then you'11 calculate the average size of the countries that are include d in the input file smallest- if the word smallest comes after the size command, then you'11 find and display the smallest of the countries that are in cluded in the input file largest if the word largest comes after the size command, then you'1l find and display the largest of the countries that are inclu ded in the input file country - the country command will be followed by a string that could represent a country code from the file You'1l search through the input file and if you find the given country code, then you'11 display the information about that country neighbors the neighbors command will be followed by a string that could represent a country code from the file. You'1l search through the input file and if you find the given country code in the neighbors list for a country that's included in the input, then you'11 dis play the information about that country Each of the commands has the possibility for nothing to be found and displayed. So there will be responses for those. Look lower to see what to do in those case Here's a sample of what the input could for the commands could look like Data File: countryInfo.txt ize average size largest size smallest country US neighbors US country NONE neighborS WHO https canvas.vt.edulcourses 41012assignments/156216 1/8Explanation / Answer
package com.java2novice.algos;
public class MyBinarySearch {
public int binarySearch(int[] inputArr, int key) {
int start = 0;
int end = inputArr.length - 1;
while (start <= end) {
int mid = (start + end) / 2;
if (key == inputArr[mid]) {
return mid;
}
if (key < inputArr[mid]) {
end = mid - 1;
} else {
start = mid + 1;
}
}
return -1;
}
public static void main(String[] args) {
MyBinarySearch mbs = new MyBinarySearch();
int[] arr = {2, 4, 6, 8, 10, 12, 14, 16};
System.out.println("Key 14's position: "+mbs.binarySearch(arr, 14));
int[] arr1 = {6,34,78,123,432,900};
System.out.println("Key 432's position: "+mbs.binarySearch(arr1, 432));
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.