Find the value in the unsorted array and the sorted array

Assignment Help Business Management
Reference no: EM132064505

Part 1:  Create a new project Lab5Part1. This part is going to be based on Lab4Part1 anduse two one-dimensional arrays with data read in from a file.These arrays will be the TopNumber and TopName arrays from Lab4Part1.  However, the data that the arrays read from will be unordered from a new data file, SciFiFantasyYearMix.txt.

You will read in the data from the file just as before.  Next print the unordered data from the arrays.  Use the same menu printing format as from Lab4Part1, i.e. all the numbers and titles in a table.   Sort the data in the arrays using a bubble sort method then print the array data again for the user to choose from.  Let the user choose and use linear search to print the user's choice and the associated name.

You must write a method that uses the bubble sort algorithm to sort the numeric array.  As you sort the numeric array, you must also sort the names array at the same time.  Your bubble sort method should take in the TopNumber and TopNames arrays and the MAXITEMS value as the input parameters. Save this program as Lab5Part1.java and put two test runs in your answers file.

Part 2: Create a new project Lab5Part2.  Copy the code from Lab5Part1 into the project.  Change the arrays TopName and TopNumber into ArrayLists instead of arrays.  Instead of calling your bubble sort array, use the built-in sort mechanism to sort TopNumber.  Use the input file SciFiFantasySearchable2.txt to test with.  Then test with the file CandySearchable.txt . Save this program as Lab5Part2.java and put the two test runs in your answers file.

2.a) In your Lab5Part2 file, can you sort the TopName array with the TopNumber array?  Why or why not?  Put your answer in your answer file.

Part 3: Create a new project Lab5Part3.  Copy Lab5Part1 into the project.NOTE: use arrays not ArrayLists.  Create a new bubble sorting method that sorts the name strings instead of the numbers.  Follow the same steps as Lab5Part1 but call the string sorting method instead of the number sorting method.  Use the same input files as Lab5Part2 to test.  Save this program as Lab5Part3.java and put two test runs in your answers file]

Part 4: Create a new project Lab5Part4.  Read in the numeric data from SciFiFantasySearchables2.txt  Ask the user to pick a value between 0 and the maximum numeric value from the file and have your program determine if it is in the array.

4.a) Create a new project Lab5Part4a from Lab5Part4.   Write a method that takes in the array and the user input and determines if the value is in the array by using linear search.  If it is the array, return the index of the array location.  If it is not in the array, return -1.  Print the location of the user's input value in the unsorted array.  Next print the unsorted array values out in a table with 40 rows of 5 values each.  Use formatted output to make this table.  Call the bubble sort method from Lab5Part1 to sort the array and print the values again.  Call the linear search method again to determine where the user's value is in the sorted array and output the location.

4.b) Create a new project Lab5Part4b from Lab5Part4.   Write a method that takes in the array and the user input and determines if the value is in the array by using binary search.  If it is the array, return the index of the array location.  If it is not in the array, return -1.  Print the location of the user's input value in the unsorted array. Next print the unsorted array values out in a table with 40 rows of 5 values each.  Use formatted output to make this table.  Call the bubble sort method from Lab5Part1 to sort the array and print the values again.  Call the binary search method again to determine where the user's value is in the sorted array and output the location.

4.c) Did linear search find the value in the unsorted array and the sorted array?  Why or why not?  Put your answer in your answers file.

4.d) Did binary search find the value in the unsorted array and the sorted array?  Why or why not? Put your answer in your answers file.

Extra credit tasks if desired.  All extra credit is optional:

XC1)  Measure time for the sorting methods in 4a and 4b.  Create new project Lab5XC1 that creates two intArrayLists of size 5000 that get the same unsorted values stored in them.  Use the first array and call a modified bubble sort method for ArrayLists to sort it and use the second array to call the built-in quick sort method for ArrayLists. 

For each method, use the Java Instant class to find the instant before the method is called, then another Instant when the method returns to the caller, then subtract the two and print the value to give a measurement of the run time of the method.

Put your program in a loop that runs the entire process 5 times, i.e. creates 5 unique unsorted arrays.  Capture the run times of the methods in a 2D array and after the 5 iterations are done, print a table of the times.  Make sure the label the columns and rows of your output table.

XC2)  Write a method that implements Quicksort withthe Hoare partition scheme for int arrays.  Replace the bubble sort method in Lab5Part4b.java with this quicksort method and test as described.

XC3) Write a program that reads in and stores the data from SciFiFantasySearchable2.txt and then prints the table of unsorted data to an output file.  Next, sort the array by the numeric data and print this sorted array to the output file.  Finally, sort the array by the name data and print this sorted array to the output file.  The output file should end with all three tables of the data in the output file.  NOTE: There are many ways to create and write to output files in Java.  One of the simplest ways to do this is to connect a File , ex.out.txt, to a PrintStream, ex. outFile,  and then set up this PrintStream as the designated output stream with the command System.setOut(outFile);

XC4)Write a program to create an integer array or ArrayListof size 2000 and fill it with random numbers between 0 and 10000 using the Random class or the Math.Random class to generate the values.  Ask the user to pick a value between 0 and 10000 and your program will determine if it is in the array.  Use linear search first, then sort the array with Java's qsort and search again with binary search.

Reference no: EM132064505

Questions Cloud

Contribute to the future of tourism development : THE ESSAY IS ABOUT GEO-TOURISM AND GEO PARKS. and then outlining how Geotourism and Geoparks will contribute to the future of tourism development.
Discuss about the concept of terrorism : Western nations, to include the United States, have been very reluctant to recognize terrorism in any way that could be construed as legitimate warfare.
Explain the benefits of using planning techniques : From the first e-Activity, identify the following CPUs: 1) the CPU that resides on a computer that you own or a computer that you would consider purchasing.
Record the journal entry on the stock options grant date : The options serve as compensation for services rendered during the first three years. Record the journal entry on the stock options grant date
Find the value in the unsorted array and the sorted array : Did binary search find the value in the unsorted array and the sorted array? Why or why not? Put your answer in your answers file.
Demonstrate the use of poswershell objects : Write 10 scripts to demonstrate the use of PoswerShell objects. Please make sure all scripts are useful to Operating Systems functionality
What is the role of law enforcement in these programs : How do community-based programs address issues related to juvenile gang violence? What is the role of law enforcement in these programs?
What is the total amount to be classified : What is the total amount to be classified and expensed as research and development in 2015? Be sure to display your calculations in detail
Discuss challenges and pitfalls of different status reports : Discuss the challenges and pitfalls of different status reports. Explain the difference between the status reports provided for teams, sponsor, and steering

Reviews

Write a Review

Business Management Questions & Answers

  Market characteristics of perfect competition

1.) Identify and describe the market characteristics of perfect competition. 2.) Explain price competition in perfect competition.

  What are the equilibrium price and quantity

If the U.S. prohibits the importation of this product, what are the equilibrium price and quantity?

  Assess how useful differences in national cultures

Using an example of a culture you are familiar with, assess how useful differences in national cultures are for doing business globally?

  Approach a decision from a group perspective

Suggest a scenario that illustrates when a manager should approach a decision from a group perspective, as opposed to taking his or her individualized approach

  Elucidate how can hr professionals develop the needed skills

Elucidate how can HR professionals develop the needed skills to analyze also interpret metrics. Illustrate what resources could an HR professional consult to begin building expertise in this area.

  Identifying business methods to resolve issues

Intersect Investments executives are pointing fingers because of internal problems. Identify business methods that would help resolve their issues.

  A defined benefit retirement plan

A small business owner  has a defined-benefit retirement plan for him and three employees.  Discuss  the annual retirement benefit for each plan participant.

  How can agc detect potential internal and external threats

How can AGC detect these potential internal and external threats? What are methods that AGC can use to protect organization from internal and external threats?

  Legislative and judicial branches in health

legislative and judicial branches in health policyunderstanding of the legislative and judicial branches. write the

  Explain your rationale for selection of your chosen market

Discusses your rationale for the selection of your chosen market. Your rationale should be justified with a more detailed discussion of your analysis of the macro-environmental factors of your chosen market which you have presented in the appendix..

  Banks play role in changing monetary supply

Assume the bank received a cash deposit of $20,000 What is the immediate impact of this transaction on the money supply. and or its composition explain.

  How is harassment a dilemma though

Which you then talk about in terms of giving notice to the employee. How is harassment a "dilemma", though? And how is it a dilemma for the corporation?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd