Question

Assignment 5 will be way different. It will be more like what you will receive in a programming shop. By that I mean that some things are built for you and others you will need to create or finish. P.S. part of your grade will include: Did you add in the required files? Did you rename your project? does your linear searches work? Did you put your code in the correct modules? did you change modules that you weren't supposed to? Build a program using what I gave you as a starting point

  • Do not add any modules; just use the ones I provide and add the code necessary to make it run
  • Don't change any module names or the code in that module which has a comment block at the beginning which says "Finished - Don't alter!"
  • You are required to add code and/or finish modules with a comment block at the beginning which says "Finish adding Code"
  • The array has 10,000 integer elements and is filled for you by calling the module FillTheArray()
  • The range of number that will fill the array is from 0 to 2500
  • The array is unsorted, and a number may appear from 0 to many, many times
  • Build 2 linear searches
  • 1320 is just an integer value I selected which is between 0 and 2500
  • The first linear search will check for the existence of the number 1320
  • The second linear search will see how many of the number 1320 is actually exists in the array
  • HINT: Because the function Random() is used to fill the array, the amount of the number 1320 will be different each time. This is why you need to validate your code and not just assume it is working correctly. This means you may need to build build your logic on a small array with known values in it and then apply it to the large array I have provided
  • Output for the program will be simple and only states if 1320 exists or not in the array and then if it does, how many of them are there in the array
  • Finish filling out the explanation in the Main() labeled "Array as an agreement comment:". What I'm asking for here is in this comment you to explain how the array is passed into the module, filled and available in the Main() yet it is not returned
  • Don't forget to:
    • rename the "starter code"
    • add the validator file so you can get any information you need
    • to add your Heading file and call it at the beginning of main
    • a separate program to by module FillTheArray()

The following are my thoughts on how to deal with weeks program. Im doing this because this is a real-world kind of solutio

number 1320. This means that the condition would look like this (Ifound && index SIZE). Dont forget that found a false and

java

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Java code

import java.util.Random;

public class Main {
    public static void main(String[] args)
    {
        final int SIZE = 100000, ENTRY = 1320;
        int [] iNumArray = new int[SIZE];
        //Fill the array with random numbers
        //from 0 -2500
        fillTheArray(iNumArray,SIZE);
        //first linear Search
        boolean status = linearSearchOne(iNumArray,SIZE,ENTRY);
        if(status)
        {
            //Call second linear Search
            int n =linearSearchTwo(iNumArray,SIZE,ENTRY);
            System.out.println(n+ " entries found of "+ENTRY);
        }
        else
        {
            System.out.println("No entries found for "+ENTRY);
        }


    }
    public static void fillTheArray(int[] iTempArray, int size)
    {
        Random random = new Random();
        for (int i = 0; i <size ; i++) {
            //fill the array is from 0 to 2500
            iTempArray[i] = random.nextInt(2500);
        }

    }
    public static boolean linearSearchOne(int[] iTempArray, int size, final int ENTRY)
    {
        boolean found = false;
        int index =0;
        while (!found && index<size)
        {
            if(iTempArray[index]== ENTRY)
                found = true;
            index++;
        }
        return found;
    }
    public static int linearSearchTwo(int[] iTempArray, int size, final int ENTRY)
    {
        int iHowManyExist=0;
        for (int i = 0; i <size ; i++) {
            if(ENTRY == iTempArray[i])
                iHowManyExist++;
        }
        return iHowManyExist;
    }
}

//Output

C:\Program Files\Java\jdk1.8.0_221\bin\java.exe ... 48 entries found of 1320 Process finished with exit code o

//If you need any help regarding this solution......... please leave a comment ...... thanks

Add a comment
Know the answer?
Add Answer to:
Assignment 5 will be way different. It will be more like what you will receive in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C programming (you don't need to write program) Problem 1 [Linear Search with Early Stop] Below...

    C programming (you don't need to write program) Problem 1 [Linear Search with Early Stop] Below you will find a linear search function with early stop. A linear search is just a naive search - you go through each of the elements of a list one by one. Early stop works only on sorted list. Early stop means, instead of going through whole list, we will stop when your number to search can no longer be possibly found in the...

  • ***Please give the java code for the below and add comments for different areas for a...

    ***Please give the java code for the below and add comments for different areas for a dummy to understand*** This java program will combine the techniques of handling arrays, decision control statements, and loops. Your program should accomplish the following: Build an array that holds characters (size 35) Load the array with random capital letters (use random generator) Your program should present a menu to the user allowing for the following “actions”. To “search” for a target letter of the...

  • C++ code The assignment has two input files: • LSStandard.txt • LSTest.txt The LSStandard.txt file contains...

    C++ code The assignment has two input files: • LSStandard.txt • LSTest.txt The LSStandard.txt file contains integer values against which we are searching. There will be no more than 100 of these. The LSTest.txt file contains a set of numbers that we are trying to locate within the standard data set. There will be no more than 50 of these. Read both files into two separate arrays. Your program should then close both input files. All subsequent processing will be...

  • // Program takes 5 numbers from a user (from console), stores them into an // array,...

    // Program takes 5 numbers from a user (from console), stores them into an // array, and then prints them to the screen (on the same line). // Add code to complete this program. You only need to add code where indicated // by "ADD HERE". #include <iostream> using namespace std; int main() { const int SIZE = 5; // size of array // ADD HERE - create an array of integers that will hold 5 integers. cout << "please...

  • The purpose of this assignment is to familiarize you with sort algorithms. Problem Description is as follows: 8. Search Benchmarks Write a program that has at least 20 250 integers stored in an ar...

    The purpose of this assignment is to familiarize you with sort algorithms. Problem Description is as follows: 8. Search Benchmarks Write a program that has at least 20 250 integers stored in an array in ascending order. It should call a function that uses the linear search algorithm to locate one of the values. The function should keep a count of the number of comparisons it makes until it finds the value. The program then should call a function that...

  • Step 1. Start Netbeans and create a project called ArrayLab Step 2. Write the main method...

    Step 1. Start Netbeans and create a project called ArrayLab Step 2. Write the main method  Declare and initialize an array called myNums int myNums = {3, 8, 12, 4, 2, 9, 6};  Declare an int called largestNum and set it to 0.  Write a for loop that prints the array for (int index = 0; index < myNums.length; index++) { System.out.println(myNums[index] + “ “); }  Write a for loop that prints the array backwards ...

  • Array lists are objects that, like arrays, provide you the ability to store items sequentially and...

    Array lists are objects that, like arrays, provide you the ability to store items sequentially and recall items by index. Working with array lists involves invoking ArrayList methods, so we will need to develop some basic skills. Let's start with the code below: The main method imports java.utii.ArrayList and creates an ArrayList that can hold strings by using the new command along with the ArrayList default constructor. It also prints out the ArrayList and, when it does, we see that...

  • C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) L...

    C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) Last Name (char[]) Age (int) Height in Inches (double) Weight in Pounds (double) You will use pass-by-reference to modify the values of the arguments passed in from the main(). Remember that arrays require no special notation, as they are passed by reference automatically, but the other...

  • You will be reading in 3 files in the program. One will contain a list of...

    You will be reading in 3 files in the program. One will contain a list of 1000 words in unsorted order. The second file will contain 1000 words in sorted order. The final file will contain 20 words to be searched for. The main program has been written for you. You will be implementing three functions: bool readWords(string array[], int size, string fileName); int linearSearch(string wordToFind, const string words[], int size); int binarySearch(string wordToFind, const string words[], int size); The...

  • Array Class Assignment

    This is a two-part assignment. It is better to submit the files for both parts when you are done than to submit part 1 first and part 2 later.In the Array.h file includes the class definition and member functions implementations.PART 1Write And Test An Array Class [Array.TestDriver.cpp] Write a data structures class. The resulting class can be used in any program in place of a C++ array, in case you want the advantages of range safety and built-in size tracking.Requirements....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT