Question

In Java, Prompt the user for two characters. Output the movies that begin with those two...

In Java,

Prompt the user for two characters. Output the movies that begin with those two characters.

Files in the same directory: db.txt

Standard Input: Vo

Required Output:

Movie search by characters. Enter two characters.\n
Movies that start with Vo\n
Vo svetot na bajkite 2\n
Vo svetot na bajkite\n
Voces a 45\n
Voces de la democracia\n
Voces de oro\n
Voces sin voz\n
Voces\n
Voces\n
Voc� Bonita\n
Voc� Est� Aqui\n
Voc� na TV!\n
Vodacom Superstar\n
Vodafone TBA\n
Voennyy gospital\n
Voetbal International\n
Voetbal International\n
Voetbal International\n
Voetbal insite\n
Voetbal insite\n
Voetbalvrouwen\n
Vogaverk\n
Vogel und Osiander\n
Vogel und Osiander\n
Voice - Danmarks st�rste stemme\n
Voice - Danmarks st�rste stemme\n
Voice: Inochi naki mono no koe\n
Voicemail\n
Voices Against Them\n
Voices Among Us\n
Voices in Time\n
Voices\n
Voici venir l'orage...\n
Voimala\n
Vointa de Femeie\n
Voisin, voisine\n
Voitheia geitonoi\n
Vojna akademija\n
Vojna akademija\n
Vojnici\n
Voksdugen\n
Voksenundervisning\n
Vokzal\n
Vol 272\n
Vol State Presents\n
Volcanic Vacations\n
Volcano Live\n
Volcano: The Series\n
Volcanoes: A Window Into Geological Time\n
Volgens hem, volgens haar\n
Volim Hrvatsku\n
Volim i ja nerandze... no trpim\n
Volite se ljudi\n
Volker Pispers und G�ste\n
Voll erwischt\n
Voll erwischt\n
Voll total\n
Voll witzig!\n
Volle Kanne\n
Volle Kanne\n
Volle zalen\n
Volles Haus\n
Vollgas!\n
Volny chernogo morya\n
Volora!\n
Volpone\n
Volsebniot voz\n
Volsebnoto samarce\n
Volt\n
Volt\n
Volt\n
Volta\n
Volta\n
Volta\n
Volta\n
Voltea pa' que te enamores\n
Volti. Viaggio nel futuro d'Italia\n
Voltron Force\n
Voltron Force\n
Voltron: Defender of the Universe\n
Voltron: Defender of the Universe\n
Voltron: Defender of the Universe\n
Voltron: The Third Dimension\n
Voltron: The Third Dimension\n
Voltron: The Third Dimension\n
Voluharji\n
Voluharji\n
Volume One\n
Volume One\n
Volume One\n
Volumen 2\n
Volumen\n
Volumz\n
Volumz\n
Volumz\n
Voluntary Service Overseas\n
Volver a empezar\n
Volver a empezar\n
Volver a m�\n
Volver a nacer\n
Volver a vivir\n
Volver al para�so\n
Volver con...\n
Volveremos\n
Vom Ahorn bis zur Zwiebel - Pflanzen in unserer Umgebung\n
Vom Gl�ck verfolgt\n
Vom Pionier zum Million�r\n
Vom Webstuhl zur Weltmacht\n
Vom eigenen Vater entf�hrt - M�tter k�mpfen um ihre Kinder\n
Von 5 auf 2\n
Von 5 auf 2\n
Von Liebe keine Rede\n
Von Mann zu Mann\n
Von Melodie zu Melodie\n
Von Null Uhr Eins bis Mitternacht - Der abenteuerliche Urlaub des Mark Lissen\n
Von Null auf 42\n
Von Rom zu Rhein - Die R�mer\n
Von den Sockeln\n
Von uns f�r Sie\n
Von's Room\n
Vonkalat\n
Voo Directo\n
Voo Directo\n
Voo Directo\n
Voor boer en tuinder\n
Voor de vuist weg\n
Voorstelling\n
Voorstelling\n
Vorfahren gesucht\n
Voroniny\n
Vorotily\n
Vorsicht - keine Engel!\n
Vorsicht Kamera - Das Original\n
Vorsicht Kamera - Das Original\n
Vorsicht Kamera\n
Vorsicht Musik!\n
Vorsicht! Falke!\n
Vorsicht! Friedman\n
Vorsicht! Frisch gewachst!\n
Vorsicht, Falle!\n
Vorsicht, Falle!\n
Vorsicht...! Der Comedy-Ratgeber von A bis Z\n
Vorsingen\n
Vortech: Undercover Conversion Squad\n
Vortech: Undercover Conversion Squad\n
Vortech: Undercover Conversion Squad\n
Vortegh eir, mard astzo?\n
Vortex\n
Vorw�rts in die Vergangenheit\n
Vorw�rts in die Vergangenheit\n
Voskresene, polovina sedmogo\n
Voskresene, polovina sedmogo\n
Vost� jutja\n
Vost� pregunta\n
Votana, mystika kai therapeies\n
Vote for Them\n
Votka portokali\n
Voto por voto\n
Vourate Geitonoi\n
Vous aurez le dernier mot\n
Vous les femmes\n
Vous n'allez pas le croire!\n
Vous ne r�vez pas!\n
Vous ne r�vez pas!\n
Vovkulakiya, ili zagadka doktora Nikodima\n
Vovkulakiya, ili zagadka doktora Nikodima\n
Vox pop\n
Voxtours Extrem\n
Voxtours\n
Voyage Trekkers\n
Voyage entre les lignes\n
Voyage to the Bottom of the Sea\n
Voyage to the Bottom of the Sea\n
Voyage to the Planets\n
Voyage � Walt Disney World\n
Voyager\n
Voyagers!\n
Voyagers!\n
Voyagers!\n
Voyages of Discovery\n
Voydi v kazhdyy dom\n
Voyna\n
Voz viva de los universitarios\n
Vozes do Wrestling\n
Vozvrashchenie Budulaya\n
Vozvrashchenie Mukhtara\n
Number of matches: 185\n
0 0
Add a comment Improve this question Transcribed image text
Answer #1

solution;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class MoviesSearch {
  
private static final String FILE_NAME = "db.txt";
public static void main(String[] args)
{
File file = new File(FILE_NAME);
Scanner fileScanner, in;
String toSearch, line;
int numberOfMatches = 0;
boolean match = false;
  
System.out.print("Movies search by characters.\nEnter 2 characters: ");
in = new Scanner(System.in);
toSearch = in.nextLine().trim();
while(toSearch.length() <= 0 || toSearch.length() > 2)
{
System.out.println("\nInput length must be of 2 characters.");
System.out.print("Movies search by characters.\nEnter 2 characters: ");
toSearch = in.nextLine().trim();
}
  
System.out.println("\nMovies that start with " + toSearch + ": ");
try {
fileScanner = new Scanner(file);
while(fileScanner.hasNextLine())
{
line = fileScanner.nextLine().trim();
if(line.substring(0, 2).equalsIgnoreCase(toSearch.trim())) // cuts the first two characters of each line from the file
{
numberOfMatches++;
match = true;
System.out.println(line);
}
}
if(!match)
{
System.out.println("No match found for movie starting with " + toSearch + ".");
System.exit(0);
}
System.out.println("\nNumber of mathces: " + numberOfMatches);
  
} catch (FileNotFoundException ex) {
System.out.println("Could not find file: " + FILE_NAME);
System.exit(1);
}
}
}
*********************** SCREENSHOT ********************

Add a comment
Know the answer?
Add Answer to:
In Java, Prompt the user for two characters. Output the movies that begin with those two...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT