*JAVA
Prompt the user for a movie name. Output the three movies that come alphabetically before the one entered.
I need help correcting my code. I'm unsure why I am getting a name, year, and genre in my output.
Input: Jericho
Output:
Similar title finder. Enter a movie name.\n
Here are the 3 movies that are listed before the one you entered\n
Jeremy Paxman Interviews...\n
Jeremy Taylor\n
Jeremy Vine Meets...\n
Current output:
Similar title finder. Enter a movie name.\n
Here are the 3 movies that are listed before the one you entered\n
Jeremy Vine Meets...\n
2004\n
Documentary\n
(Your output is too short.)
Current code:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;
public class Movies {
static ArrayList<String> moviesList;
public static void main(String[] args) throws FileNotFoundException {
//providing file name
File file = new File("db.txt");
readNames(file);
System.out.println("Similar title finder. Enter a movie name.");
Scanner scanner = new Scanner(System.in);
String movieName = scanner.nextLine();
searchMovie(movieName);
}
public static void readNames(File file) throws FileNotFoundException {
moviesList = new ArrayList<String>();
Scanner scanner = new Scanner(new FileReader(file));
while (scanner.hasNextLine()) {
String name = scanner.nextLine();
moviesList.add(name);
}
}
public static void selectionSort(ArrayList<String> haystack) {
//visit all elements but the last
for (int startScan = 0; startScan < haystack.size() - 1; startScan++) {
//assume first element is smallest
int minIndex = startScan;
String minValue = haystack.get(minIndex);
//visit all remaining elements
//if current element is smaller than what we know so far
for (int index = startScan + 1; index < haystack.size(); index++) {
if (haystack.get(index).compareTo(minValue) < 0) {
//keep track of smaller element
minValue = haystack.get(index);
minIndex = index;
}
//swap smaller element into place
haystack.set(minIndex, haystack.get(startScan));
haystack.set(startScan, minValue);
}
}
}
public static void searchMovie(String name) {
if (!moviesList.contains(name)) {
moviesList.add(name);
Movies.selectionSort(moviesList);
searchMovie(name);
int index = moviesList.indexOf(name);
moviesList.remove(index);
}
if (moviesList.contains(name)) {
String data = "";
int index = moviesList.indexOf(name);
for (int i = 3; i >= 1; i--) {
if (index - i >= 0) {
data += moviesList.get(index - i) + "\n";
}
}
System.out.println("Here are the 3 movies that are listed before the one you entered");
System.out.println(data);
}
}
}
please include explanations and avoid try/catch or collections. Thank you


Can't provide a screenshot as you have not attached the database file.
*JAVA Prompt the user for a movie name. Output the three movies that come alphabetically before...
JAVA HELP: Directions Write a program that will create an array of random numbers and output the values. Then output the values in the array backwards. Here is my code, I am having a problem with the second method. import java.util.Scanner; import java.util.Random; public class ArrayBackwards { public static void main(String[] args) { genrate(); print(); } public static void generate() { Scanner scanner = new Scanner(System.in); System.out.println("Seed:"); int seed = scanner.nextInt(); System.out.println("Length"); int length = scanner.nextInt(); Random random...
please edit my java code perferably on jgrasp version 50.0 , wont complie correctly :( the program is supposed to read from my input file and do the following 1) print out the original data in the file without doing anything to it. 2) an ordered list of all students names (last names) alphabetically and the average GPA of all student togther . 3) freshman list in alphabeticalorder by last name with the average GPA of the freshmen...
JAVA: Rewrite the following code to where the inputs are from a file. The file name will be from the input from the user scanner. CODE: import java.util.*; public class Q1 { public static int sumOD (int k) { int sumOD = 0; int in = k; while (in != 0) { int digitON = in % 10; sumOD += digitON; in /= 10; } return sumOD; } public static void main(String[] args) { int n, i, k; System.out.println("Enter...
7.11 LAB: Sorting user IDs Given a main() that reads user IDs (until -1), complete the quicksort() and partition() methods to sort the IDs in ascending order using the Quicksort algorithm, and output the sorted IDs one per line. Ex. If the input is: kaylasimms julia myron1994 kaylajones -1 the output is: julia kaylajones kaylasimms myron1994 Code: import java.util.Scanner; import java.util.ArrayList; public class UserIDSorting { // TODO: Write the partitioning algorithm - pick the middle element as the // pivot,...
Help! Not sure how to create this java program to run efficiently. Current code and assignment attached. Assignment :Write a class Movies.java that reads in a movie list file (movies.txt). The file must contain the following fields: name, genre, and time. Provide the user with the options to sort on each field. Allow the user to continue to sort the list until they enter the exit option. ---------------------------------------------------------- import java.util.*; import java.io.*; public class Movies { String movieTitle; String movieGenre;...
JAVA Can you make this return the first letter of first and last name capitalized? import java.io.File; import java.io.IOException; import java.util.*; public class M1 { public static void main(String[] args) { //scanner input from user Scanner scanner = new Scanner(System.in); // System.out.print("Please enter your full name: "); String fullname = scanner.nextLine(); //creating a for loop to call first and last name separately int i,k=0; String first="",last=""; for(i=0;i<fullname.length();i++) { char j=fullname.charAt(i); if(j==' ') { k=i; break; } first=first+j;...
I have this java program that I need to add an abstract method and polymorphism to it : import java.util.Scanner; //class and encapsulation class BookTheTicket { private String movieName; private String theatreName; private int ticketCost; void myAllmovies() { System.out.println("-------Listing the movies:------"); System.out.println(" 1.DDLJ ------------ $40 \n 2.kkr---------$.50 \n 3.game-movie --------$60 \n 4.fun movie ----- $.70 "); } } // inheritence class theater extends BookTheTicket{ private int numOfTickets; void theater() { System.out.println("*******Listing the theatre:******* \n 1.coco cola tld \n 2.koi gandhi...
Language Java Step 1: Design a class called Student. The Student class should contain the following data: firstName lastName studentID totalCredits gpa Your class should implement the “sets” and “gets” for the class. Include methods: equals, compareTo, toString. Change the toString method (from class) to put each member variable on a new line. Step 2: Write a driver program to test that Student works correctly. Test is with 3 students as given in class. Step 3: Write a “registration” program...
This is my current output for my program.
I am trying to get the output to look like
This is my program
Student.java
import java.awt.GridLayout;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JFileChooser;
public class Student extends javax.swing.JFrame {
BufferedWriter outWriter;
StudentA s[];
public Student() {
StudentGUI();
}
private void StudentGUI() {
jScrollPane3 = new
javax.swing.JScrollPane();
inputFileChooser = new
javax.swing.JButton();
outputFileChooser = new
javax.swing.JButton();
sortFirtsName = new...
C++ Language I have a class named movie which allows a movie object to take the name, movie and rating of a movie that the user inputs. Everything works fine but when the user enters a space in the movie's name, the next function that is called loops infinetly. I can't find the source of the problem. Down below are my .cpp and .h file for the program. #include <iostream> #include "movie.h" using namespace std; movie::movie() { movieName = "Not...