Department of Computer Science.

Georgia State University

CSc 2310 J. L. Bhola

Spring 2015 - Assignment #7

Due Thursday, April 16th 2015

Note: (1) For all assignments, always use comments to explain your program.

(2) No copying allowed. If it is found that students copy from each other, all of these programs will get 0.

(3) You must use the name given to name your program. Should you use a different name, you would lose 10% of what each program is worth.

Objectives:

1. To gain experience with using the Java programming language by being able to build classes.

Description of program:

You are to write a program name search.java that will do the following:

a. You are to create 3 arrays - prompt the user for a number that is greater than 100 that will serve as the size for the arrays (all 3 arrays will have the same user input size).

b. Generate this amount of random numbers to fill these arrays – the random numbers must range from 1 to 99.

c. Write 1 sequential search voided function (method) name Seq_search() that accepts two parameters – 1 array and a target value to search for. Call this method 3 times à once with a target value of 1, next with a target value of 50 and next with a target value of 100. Each time you call this method, you must invoke a clock to see how long it takes to execute and print out the time with an appropriate message.

d. Write 1 binary search voided function (method) using Loop only, name Bin_search() that accepts two parameters – 1 array and a target value to search for. In the main program first sort one of the arrays and time it to see how long it took to sort. Now pass this sorted array as a parameter to this method calling it 3 times à once with a target value of 1, next with a target value of 50 and next with a target value of 100. Each time you call this method, you must invoke a clock to see how long it takes to execute and add the time it took to sort the array to this time and print out the time with an appropriate message.

e. Write 1 binary search voided function (method) that uses recursion only, name BinRe_search() that accepts two parameters – 1 array and a target value to search for. In the main program first sort the last array and time it to see how long it took to sort. Now pass this sorted array as a parameter to this method calling it 3 times à once with a target value of 1, next with a target value of 50 and next with a target value of 100. Each time you call this method, you must invoke a clock to see how long it takes to execute and add the time it took to sort the array to this time and print out the time with an appropriate message.

f. After you get the time, give an analysis as to which you think is a better algorithm to use and under what circumstance it is better to be used.

What to turn in:

Turn in:

A. A disk (flash drive) with the files search.java and search.class or search.jar

B. A printout of the search.java file.

C. Make sure your name is clearly written on both the disk and the print out.

2