Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Loop Sorting and Binary Search

xJavaLover
xJavaLover 


keeps the DVDs sorted by title. In order to produce efficient code do not use sorting to keep the DVDs sorted. Redesign method add instead, so that it inserts the DVD into a sorted collection and produces sorted collection. In addition, implement an efficient method to search for given DVD by the title. Method should be called searchForDVD. It should have only String type formal parameter that provides the title of the DVD that we are searching for. The return type should be an integer that specifies the location in the collection array of DVDs. When search is not successful method returns -1. Method searchForDVD should be in the DVD collection class. Modify main method so that at the end it also tests method searchForDVD by performing one successful and one unsuccessful search. Display the DVD found for successful search, and write an appropriate comment otherwise. YOU MUST SORT IN THE addDVD method...AND USE NO SORTING ALGORITHMS...Only a loop. Add the binary search method...and be able to search for a specific DVD in the collection and output it and one not in the collection and output it. PROGRAM RUN outline: Display all DVDs Add two more DVDs Display all DVDs Search for specific DVD that is in the collection Search for specific DVD that is not in the collection Attachments Tags
Clarifications

Answers

Java - DVD - Solution

dickersonka
dickersonka 



Attached is the solution including source and comments to the Java - DVD assignment Attachments
DVD.zip (2 K) Download
Preview
report += "\n\nDVD List:\n\n"; for (int dvd = 0; dvd < count; dvd++) report += collection[dvd].toString() + "\n"; return report; } //----------------------------------------------------------------- // Increases the capacity of the collection by creating a // larger array and copying the

Preview
Favreau", 2010, 22.99, false); movies.addDVD ("Casablanca", "Michael Curtiz", 1942, 19.95, false); System.out.println (movies); System.out.println(); System.out.println("Search for 'Iron Man 2'"); int index = movies.searchForDVD("Iron Man 2"); if(index >= 0){ System.out.println("DVD Found in position " + index); } else {

Preview
this.title = title; this.director = director; this.year = year; this.cost = cost; this.bluRay = bluRay; } //----------------------------------------------------------------- // Returns a string description of this DVD. //----------------------------------------------------------------- public String toString() { NumberFormat fmt = NumberFormat.getCurrencyInstance(); String

Movies.java (1 K) Download Preview
= movies.searchForDVD(findMovie); if(index >= 0){ System.out.println("DVD Found in position " + index); } else { System.out.println("DVD Not Found"); } System.out.println(); System.out.print("Enter movie name to search for: "); findMovie = input.nextLine(); System.out.println("Search for '" + findMovie + "'"); index

Screenshots
Purchase Answer