Java Program Help

Instructions

Assignments will not need IDs.

In this assignment, you will create a program that allows the user to choose between the following menu choices (menu-driven program):

  1. Linear Search
  2. Binary Search
  3. Bubble Sort
  4. Selection Sort
  5. Quit

Keep running the program until the user chooses to Quit. Your program will be split up into two main parts, where each part will run differently. For Options 1 and 2, you are working with searching methods by creating the movie store described below. For Options 3 and 4, you are working with sorting methods by generating 10 random numbers and then sorting it.

Searching Algorithms (Linear and Binary Search)

You are the owner of a movie store. You have the following information available in your stock (information is stored in the form of parallel arrays):

String[] movieTitle = {“Gone with the Wind”, “Star Wars”, “The Truman Show”, “The Martian”, “Blade Runner 2049”, “Dunkirk”, “Upstream Color”, “La La Land”, “The King’s Speech”, “Pirates of the Caribbean”};

int[] movieID = {110100, 121101, 133310, 145601, 156711, 164210, 169901, 175501, 180000, 199900};

double[] moviePrice = {3.32, 43.25, 54.00, 67.32, 105.00, 113.22, 20.00, 42.25, 32.11, 123.75};

int[] quantityAvailable = {11, 12, 13, 12, 14, 12, 19, 15, 18, 19};

First display() the above information to the user in a tabular format, using a void method. Your program should then ask for the movie ID and the number of movies the user wishes to purchase. You need to check to make sure that the requested quantity is available. After every purchase, you need to update the quantityAvailable array for that particular movie. Based on the movie ID provided by the user, display the following information (if the ID is found):

o Movie ID o Movie Title o Total cost of the purchase o Quantity remaining for that title

If the movie ID is not found, display a message saying so. The movie ID needs to be searched based on linearSearch() or binarySearch() (based on user choice from the menu).

Note that when using binarySearch(), there is no need to manually sort for this situation, as the movie ID’s are already sorted for you.

Sorting Algorithms (Bubble and Selection Sort)

Your program should generate 10 random numbers in the range of 1 to 500 and store them in an array. Use bubbleSort() or selectionSort() (based on the menu choice) to sort the array of numbers. Display both the unsorted and the sorted array.

Instructions: Please make sure your code has the following methods:

  • void display(String[] movieTitle, int[] movieID, double[] moviePrice): To display the contents of parallel array in a tabular format. Take in the three different arrays as parameters.
  • int linearSearch(int[] movieID, int key): To apply the linear search algorithm to search for the movie ID. Returns the index position, or -1 if not found. The key parameter should be the ID the user is searching for.
  • int binarySearch(int[] movieID, int key): To apply the binary search algorithm to search for the movie ID. Returns the index position of the found movie ID, or -1 if not found. The key parameter should be the ID the user is searching for.
  • int[] bubbleSort(int[] unsortedArray): To apply the bubble sort algorithm to sort the elements of an unsorted array. You should pass in an unsorted array as a parameter, and return the sorted array.
  • int[] selectionSort(int[] unsortedArray): To apply the selection sort algorithm to sort the elements of an unsorted array. You should pass in an unsorted array as a parameter, and return the sorted array.

You can use additional methods (optional) for other operations. Make sure your program runs until the user decides to quit the program. Your program should validate (input validation) the menu choice entered by the user, and force them to re-enter a menu choice if their original input was invalid. A bonus programming part has been provided below for extra points.

Extra Credit (Option 1): 10 points

We want to test the efficiency of our searching and sorting algorithms. To test the efficiency, calculate and display the execution (elapsed) time (in milliseconds). You need to store the time at the beginning of the execution of each sort or search algorithm. Then, you also store the time at the end of execution. The difference between these two stored times, is the execution time. You need to remember that system time is in milliseconds and you need proper formatting to display that. Also, for small datasets, the execution time will be a very small number. Make sure to show the start time, end time, and the execution time. Can you tell which searching technique is better/faster (linear search vs. binary search) and which sorting technique is better/faster (bubble sort vs. selection sort)?

Extra Credit (Option 2): 10 points

Choose one of the sorting algorithms and apply it to the movie arrays and sort them based on the quantities available from smaller to larger quantities. Remember that you need to show all the movie information including movieID, movieTitle, and moviePrice in addition to the quantityAvailable.

Important Notes

A grading rubric has been provided to you as a reference. A few important things to remember:

  1. Start working early. Do not wait till the due date to start working on your assignment.
  2. Make sure you submit a .java file. A .class file will result in grade of 0.
  3. Ask for timely help. You have various resources available (Professor, TA’s, CCI Tutors), make sure you ask for help if you are struggling with something. 4. Submit your own work!

Assignment Rubric

The assignment is worth 100 points, but you can achieve up to 120 points if you successfully complete the extra credit.

Grade Description100 pointsProgram completeness with pseudocode20Documentation: Header documentation (Author, Date, Description)15Documentation: Internal documentation (Inline Comments) Must explain important parts of program logic.10Process: Correct use of arrays in searching and sorting25Process: Correct calculations and process/logic throughout the code20Output: Well-formatted and Correct Output All values right or wrong are at least outputted. Output is clearly and formatted in an easy-to-read style.10Extra Credit20

Sample Run

  1. Linear Search
  2. Binary Search
  3. Bubble Sort
  4. Selection Sort
  5. Quit

Please enter a number between 1-5: 1 **** LINEAR SEARCH ****

Movie IDTitleCost110100Gone with the Wind3.32121101Star Wars43.25133310The Truman Show54.00145601The Martian67.32156711Blade Runner 2049105.00164210Dunkirk113.22169901My Neighbor Totoro20.00175501La La Land42.25180000The King’s Speech32.11199900Pirates of the Caribbean123.75

Please enter the movie ID you wish to purchase from the list above: 121101 How many copies you wish to purchase: 2

Movie ID: 121101

Movie Title: Star Wars

Number of movies bought: 2

Total Cost: \$86.50

Execution of this function took: 0.143 seconds.

  1. Linear Search
  2. Binary Search
  3. Bubble Sort
  4. Selection Sort
  5. Quit

Please enter a number between 1-5: 2

**** BINARY SEARCH ****

Movie IDTitleCost110100Gone with the Wind3.32121101Star Wars43.25133310The Truman Show54.00145601The Martian67.32156711Blade Runner 2049105.00164210Dunkirk113.22169901My Neighbor Totoro20.00175501La La Land42.25180000The King’s Speech32.11199900Pirates of the Caribbean123.75

Please enter the movie ID you wish to purchase from the list above: 121101 How many copies you wish to purchase: 2

Movie ID: 121101

Movie Title: Star Wars

Number of movies bought: 2

Total Cost: \$86.50

Execution of this function took: 0.215 seconds.

  1. Linear Search
  2. Binary Search
  3. Bubble Sort
  4. Selection Sort
  5. Quit

Please enter a number between 1-5: 3

**** BUBBLE SORT ****

The unsorted array is: 384 387 278 416 294 336 387 493 150 422

The sorted array is: 150 278 294 336 384 387 387 416 422 493

Execution of this function took: 0.018 seconds.

  1. Linear Search
  2. Binary Search
  3. Bubble Sort
  4. Selection Sort
  5. Quit

Please enter a number between 1-5: 4

**** SELECTION SORT ****

The unsorted array is: 363 28 191 60 264 427 41 427 173 237

The sorted array is: 28 41 60 173 191 237 264 363 427 427

Execution of this function took: 0.016 seconds.

  1. Linear Search
  2. Binary Search
  3. Bubble Sort
  4. Selection Sort
  5. Quit

Please enter a number between 1-5: 5




***PLEASE TRY TO DO EXTRA CREDIT AS WELL

***THIS IS AN INTRO TO JAVA CLASS PLEASE DO NOT CODE ANYTHING FANCY, USE BASIC SKILLS (ARRAYS)

Get Help With a similar task to - Java Program Help

Login to view and/or buy answers.. or post an answer

Related Questions

Similar orders to Java Program Help
43
Views
0
Answers
PG2 – LAB 2: BLACKJACK OBJECTS
CONTENTS Overview........................................................................................................................................................................2 Part A - Classes......................................................
24
Views
0
Answers
Excel Project with Documentation
In a new sheet, create one-variable data tables for these food items. For each previously selected food item, create a two-variable data table that calculates the amounts of calories based on various portion sizes and the number of portions. I have att...
52
Views
0
Answers
Computer Vision - (Machine Learning, Artificial Intelligence field) assignment in python
Video processing, image processing, object detection, object tracking, background removel. It needs to be in PYTHON. Objective The goal of this project is to develop an automatic system for video analysis of footages for the game of curling. The system...
19
Views
0
Answers
Writing and understanding simple java program code
I need help writing a java program with an Eclipse IDE. Once written I need to identify, objects, lists, algorithms, set of instructions, anything that explains how the code is written, what it does, and how an end user will use it...