Question

In java Okay, I asked this question once and the person who created the code forgot...

In java

Okay, I asked this question once and the person who created the code forgot that this file "db.txt" has hundreds of movies with ! and ' cases

Enter two years. Print movies that were released in those years and that have a name that's less than 6 characters.

Input

1974 1976

output

Movie search by year range. Enter two years.\n
Movies with short names that were released between 1970 and 1974\n
I dag\n
Izumi\n
Jamie\n
Jamie\n
Julie\n
Julie\n
Kako\n
Kako\n
Kate\n
Kojak\n
Kojak\n
Kojak\n
Kojak\n
Kojak\n
Leeds\n
Maude\n
Meshi\n
Mily\n
Nakia\n
Nakia\n
Nakia\n
Nakia\n
Nancy\n
Nanou\n
Tang\n
Them\n
Timo\n
Toma\n
Toma\n
Toma\n
Toma\n
Totte\n
Trial\n
UFO\n
UFO\n
Yak\n
Yak\n
Zoom\n
Zut!\n
Number of matches: 39\n

If the year entered is out of range, output

Movie search by year range. Enter two years.\n
Movies with short names that were released between 2050 and 3000\n
No matching movies found!\n
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code :

import java.io.*;
import java. util. Scanner;

public class movieList {
       
   /**
   * Opens and reads a file,
   */
   public static int findMovieList(File file, int year1, int year2)
   throws IOException
   {
      BufferedReader reader = new BufferedReader(new FileReader(file));
      String line;                    //Extract lines from the db.txt
      int match = 0;                 //Match counter..
      StringBuilder sb = new StringBuilder();
      System.out.print("\n Movies with short names that were released between " + year1 + " and "+ year2 + ": \n");
      while ((line = reader.readLine()) != null)
      {
        sb.append(line + "\n");
      
        String[] values = line.split(";");        //Splitting Data from the file..
        int year = Integer.parseInt(values[0].trim());   //Storing the year
        if (year ==(year1) || year ==(year2))        //Checking the year1 and year2
           if(values[2].length() < 6) {             //Checking length of the movie < 6
               System.out.println((values[2]));     //Print only the year1 & yer2 movie's names
               match = match + 1;                 //Counts total number of matches:
           }
      }

      reader.close();           //Close the reader..
      return match;   
   }
  
   public static void main(String[] args)throws Exception
      {
      // We need to provide file path as the parameter:
      // double backquote is to avoid compiler interpret words
      // like \test as \t (ie. as a escape sequence)
  
      File file = new File("/home/Desktop/java/db.txt");         //Please provide your path to the file...
      System. out. print( "Movie search by year range.\n\nEnter two years : ");
  
      int year1;
      int year2;
  
      Scanner sc = new Scanner(System.in).useDelimiter("\\s");
      year1 = sc.nextInt(); // It will not leave until the user enters data.
      year2 = sc.nextInt(); // We can read specific data.
  
      int match = findMovieList(file, year1,year2); //Function call to find movies..
      if (match == 0 )
          System.out.print("\n No matching movies found! ");
      else
          System.out.println("\n Number of matches: " + match);
      sc.close();
      }
}
  

input db.txt: (Sample for this program)

    1990;111;Tie Me Up! Tie Me Down!;Comedy;Banderas, Antonio;Abril, Victoria;ALmo 1991;113;High Heels; Comedy;Bosé, Miguel;Abril, Victoria;Almodóvar, Pedro;68;Nc 1983;104;Dead Zone, The;Horror;Walken, Christopher;Adams, Brooke;Cronenberg, D 1979;122; Cuba;Action;Connery, Sean;Adams, Brooke; Lester, Richard; 6; No; seanCo 1978;94; Days of Heaven; Drama;Gere, Richard;Adams, Brooke;Malick, Terrence;14;N 1983;140;Octopussy;Action; Moore, Roger;Adams, Maud;Glen, John;68;No;Nicholasca 1984;101;Target Eagle;Action; Connors, Chuck;Adams, Maud; Lona, José Antonio de 1979:99;Angel; Baptism of Blood, The;Drama;Bergen, Robert D.;Adams, Trudy; Seba 1985;104; Subway;Drama; Lambert, Christopher;Adjani, Isabelle;Besson, Luc;6; No; 1990;149;Camille Claudel;Drama;Depardieu, Gérard;Adjani, Isabelle;Nuytten, Bru 1982;188; Fanny and Alexander;Drama;Ahlstedt, Börje;Adolphson, Kristina;Bergman 1982;117;Tragedy of a Ridiculous Man;Drama; Tognazzi, Ugo;Aimee, Anouk; Bertoluc 1966;103;A Man & a Woman; Drama;Trintignant, Jean- Louis;Aimee, Anouk;Lelouch, 1966;103;AMan!;Drama; Trintignant, Jean-Louis;Aimee, Anouk;Lelouch, claude;46;

Output:

___________________________________________________________________________________________

Please upvote if you are satisfied with this solution...

Add a comment
Know the answer?
Add Answer to:
In java Okay, I asked this question once and the person who created the code forgot...
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