Question

Java Programming Create a program named MovieTest The program will create 10 Movie objects and place...

Java Programming

Create a program named MovieTest

The program will create 10 Movie objects and place them in an array or ArrayList of type Movie.

The program must do the following (all in main):

  • Create an array or ArrayList of type Movie.
  • Use the data in the text file that is in the download for the Movie file to create 10 Movie objects. Store the 10 Movie objects in the array or ArrayList. You MUST use the date in the text file to create the objects.
  • Use an enhanced for loop to display all movies in the array or ArrayList. Call the toString method on each Movie object and display the String returned from toString..
  • Search the array or ArrayList for the highest and lowest rated movies and display them, clearly labeled.
  • ALL OUTPUT MUST BE CLEARLY LABELED. Use the command prompt window (terminal).

Movie.java

// Movie class
// Place mandatory comments here:

public class Movie {
// instance variables
private String title;
private String releaseDate;
private double rating;
private String overview;
  
// constructor
public Movie(String title, String releaseDate, double rating, String overview) {
    this.title = title;
this.releaseDate = releaseDate;
this.overview = overview;
if(rating > 0 && rating <= 10.0) // validate parameter
    this.rating = rating;
}

// return title
public String getTitle() {
    return title;
}

// return overview
public String getOverview() {
    return overview;
}

// return release date
public String getReleaseDate() {
    return releaseDate;
}

// return rating
public double getRating() {
    return rating;
}

// update rating
public void setRating(double rating) {    
    if(rating > 0 && rating <= 10.0) // validate parameter
    this.rating = rating;
}

// return formatted release date
public String getFormattedReleaseDate() {
    // format date as MM/DD/YYYY and return
    // Do NOT update stored releaseDate.
   
}

public String toString() {
    // Use String.format to create a String containing all Movie info.
    // Call wrapString to format the overview. Use newline as the delimiter.
    // Call getFormattedReleaseDate to get date in MM/DD/YYYY format.
    // Be sure to clearly label all data. Return the String.
   
}

// Format a long String for display over multiple lines.
// The length is the number of characters on a line.
public static String wrapString(String string, String delimiter, int length) {
       String result = "";
       int lastDelimPos = 0;
       for (String token : string.split(" ", -1))
       {
           if (result.length() - lastDelimPos + token.length() > length)
           {
               result = result + delimiter + token; // insert delimiter
               lastDelimPos = result.length() + 1;
           }
           else
           {
               result += (result.isEmpty() ? "" : " ") + token;
           }
       }
       return result;
   }
}

movies.txt

Terminator: Dark Fate
2019-11-01
6.6
More than two decades have passed since Sarah Connor prevented Judgment Day, changed the future, and re-wrote the fate of the human race. Dani Ramos is living a simple life in Mexico City with her brother and father when a highly advanced and deadly new Terminator - a Rev-9 - travels back through time to hunt and kill her. Dani's survival depends on her joining forces with two warriors: Grace, an enhanced super-soldier from the future, and a battle-hardened Sarah Connor. As the Rev-9 ruthlessly destroys everything and everyone in its path on the hunt for Dani, the three are led to a T-800 from Sarahís past that may be their last best hope.
  
Doctor Sleep
2019-11-08
7.1
A traumatized, alcoholic Dan Torrance meets Abra, a kid who also has the ability to "shine." He tries to protect her from the True Knot, a cult whose goal is to feed off of people like them in order to remain immortal.
  
Frozen II
2019-11-22
7.2
Elsa, Anna, Kristoff and Olaf are going far in the forest to know the truth about an ancient mystery of their kingdom.
  
Midway
2019-11-08
5.3
The story of the soldiers and aviators who helped turn the tide of the Second World War during the iconic Battle of Midway in June 1942.
  
Last Christmas
2019-11-08
7.9
Kate is a young woman subscribed to bad decisions. Her last date with disaster? That of having accepted to work as Santa's elf for a department store. However, she meets Tom there. Her life takes a new turn. For Kate, it seems too good to be true.
      
The Irishman
2019-11-01
8.8
World War II veteran and mob hitman Frank "The Irishman" Sheeran recalls his possible involvement with the slaying of union leader Jimmy Hoffa.
      
Hustlers
2019-09-13
6.2
A crew of savvy former strip club employees band together to turn the tables on their Wall Street clients.
  
The Good Liar
2019-11-15
0
An aging con artist cannot believe his luck when he meets a wealthy widow and marks her as his next target. But she hides a secret of her own.
  
Motherless Brooklyn
2019-11-01
7.1
Lionel Essrog, a private detective living with Tourette syndrome, ventures to solve the murder of his mentor and best friend - a mystery that carries him from the gin-soaked jazz clubs of Harlem to the slums of Brooklyn to the gilded halls of New York's power brokers.
      
Harriet
2019-11-01
7.8
The story of Harriet Tubman, who helped free hundreds of slaves from the South after escaping from slavery herself in 1849.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Note:I have kept the text file inside the src folder

//Movie.java

public class Movie {
// instance variables
   private String title;
   private String releaseDate;
   private double rating;
   private String overview;

// constructor
   public Movie(String title, String releaseDate, double rating, String overview) {
       this.title = title;
       this.releaseDate = releaseDate;
       this.overview = overview;
       if (rating > 0 && rating <= 10.0) // validate parameter
           this.rating = rating;
   }

// return title
   public String getTitle() {
       return title;
   }

// return overview
   public String getOverview() {
       return overview;
   }

// return release date
   public String getReleaseDate() {
       return releaseDate;
   }

// return rating
   public double getRating() {
       return rating;
   }

// update rating
   public void setRating(double rating) {
       if (rating > 0 && rating <= 10.0) // validate parameter
           this.rating = rating;
   }

// return formatted release date
   public String getFormattedReleaseDate() {
       String[] data = this.releaseDate.split("-");
      
       return data[1]+"/"+data[2]+"/"+data[0];
      

   }

   public String toString() {
       return String.format("Title : %s\nRelease date: %s\nRating : %.1f\nOverview :\n%s\n",this.title,this.getFormattedReleaseDate(),this.rating,Movie.wrapString(this.overview, "\n", 80) );
      
   }

// Format a long String for display over multiple lines.
// The length is the number of characters on a line.
   public static String wrapString(String string, String delimiter, int length) {
       String result = "";
       int lastDelimPos = 0;
       for (String token : string.split(" ", -1)) {
           if (result.length() - lastDelimPos + token.length() > length) {
               result = result + delimiter + token; // insert delimiter
               lastDelimPos = result.length() + 1;
           } else {
               result += (result.isEmpty() ? "" : " ") + token;
           }
       }
       return result;
   }
}

//MainFile

import java.io.File;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class MovieMain {

   public static void main(String[] args) {
       File f = new File("./src/movies.txt");//change address as you need
       int i = 1;
       List<Movie> movies = new ArrayList();
       Double highest,lowest;
       int highIndex=0,lowIndex=0,j;
       String title = "", releasedate = "", overview = "", line = "";
       Double rating = 0.0;
       Scanner sc = null;
       try {
           sc = new Scanner(f);
           while (sc.hasNext()) {
               overview = "";
               if (i == 1) {
                   title = sc.nextLine();
                   if (title.trim().equals(""))
                       title = sc.nextLine();
                   i = 2;
               } else if (i == 2) {
                   releasedate = sc.nextLine();
                   i = 3;
               } else if (i == 3) {
                   rating = sc.nextDouble();
                   sc.nextLine();
                   i = 4;
               } else if (i == 4) {
                   overview = sc.nextLine();
                   i = 1;
               }
               if (i == 1) {
                   movies.add(new Movie(title, releasedate, rating, overview));
               }

           }
           sc.close();

           highest=movies.get(0).getRating();
           lowest=movies.get(0).getRating();
           j=0;
           for (Movie m : movies) {
               System.out.println(m);
               if(m.getRating()>highest)
               {
                   highest=m.getRating();
                   highIndex=j;
               }
               if(m.getRating()<lowest)
               {
                   lowest=m.getRating();
                   lowIndex=j;
               }
               j=j+1;
           }
          
           System.out.println("Highest rated movie: "+movies.get(highIndex).getTitle()+" Rating: "+highest);
           System.out.println("Lowest rated movie: "+movies.get(lowIndex).getTitle()+" Rating: "+lowest);
       } catch (FileNotFoundException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       } finally {
           sc.close();
       }

   }

}

Add a comment
Know the answer?
Add Answer to:
Java Programming Create a program named MovieTest The program will create 10 Movie objects and place...
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
  • PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class...

    PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class definition. * * @author David Brown * @version 2019-01-22 */ public class Movie implements Comparable { // Constants public static final int FIRST_YEAR = 1888; public static final String[] GENRES = { "science fiction", "fantasy", "drama", "romance", "comedy", "zombie", "action", "historical", "horror", "war" }; public static final int MAX_RATING = 10; public static final int MIN_RATING = 0; /** * Converts a string of...

  • In Java: Executable Class create an array of Employee objects. You can copy the array you...

    In Java: Executable Class create an array of Employee objects. You can copy the array you made for Chapter 20. create an ArrayList of Employee objects from that array. use an enhanced for loop to print all employees as shown in the sample output. create a TreeMap that uses Strings for keys and Employees as values. this TreeMap should map Employee ID numbers to their associated Employees. process the ArrayList to add elements to this map. print all employees in...

  • no buffered reader. no try catch statements. java code please. And using this super class: Medialtemjava...

    no buffered reader. no try catch statements. java code please. And using this super class: Medialtemjava a Create the "middle" of the diagram, the DVD and ForeignDVD classes as below: The DVD class will have the following attributes and behaviors: Attributes (in addition to those inherited from Medialtem): • director:String • rating: String • runtime: int (this will represent the number of minutes) Behaviors (methods) • constructors (at least 3): the default, the "overloaded" as we know it, passing in...

  • Task #3 Arrays of Objects 1. Copy the files Song java (see Code Listing 7.1), Compact...

    Task #3 Arrays of Objects 1. Copy the files Song java (see Code Listing 7.1), Compact Disc.java (see Code Listing 7.2) and Classics.txt (see Code Listing 7.3) from the Student Files or as directed by your instructor. Song.java is complete and will not be edited. Classics.txt is the data file that will be used by Compact Disc.java, the file you will be editing. 2. In Compact Disc.java, there are comments indicating where the missing code is to be placed. Declare...

  • Concepts Tested in this Program: Class Design Constructors Objects Inheritance Program:   Design a class named Person...

    Concepts Tested in this Program: Class Design Constructors Objects Inheritance Program:   Design a class named Person and its two subclasses, Student and Employee. Make Faculty and Staff subclasses of Employee. A Person object has a name, address, phone number, and email address (all Strings). A Student Object has a class status (freshman, sophomore, junior, or senior). Define the status as a final String variable. An Employee Object has an office number, salary (both ints ), and a date hired. Use...

  • The Tokenizer.java file should contain: A class called: Tokenizer Tokenizer should have a private variable that...

    The Tokenizer.java file should contain: A class called: Tokenizer Tokenizer should have a private variable that is an ArrayList of Token objects. Tokenizer should have a private variable that is an int, and keeps track of the number of keywords encountered when parsing through a files content. In this case there will only be one keyword: public. Tokenizer should have a default constructor that initializes the ArrayList of Token objects Tokenizer should have a public method called: tokenizeFile tokenizeFile should...

  • JAVA Use the class, Invoice, provided to create an array of Invoice objects. Class Invoice includes...

    JAVA Use the class, Invoice, provided to create an array of Invoice objects. Class Invoice includes four instance variables; partNumber (type String), partDescription (type String), quantity of the item being purchased (type int0, and pricePerItem (type double). Perform the following queries on the array of Invoice objects and display the results: Use streams to sort the Invoice objects by partDescription, then display the results. Use streams to sort the Invoice objects by pricePerItem, then display the results. Use streams to...

  • Help! Not sure how to create this java program to run efficiently. Current code and assignment...

    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) Use the Pet.java program from the original problem (down below) Compile it. Create a text...

    (JAVA) Use the Pet.java program from the original problem (down below) Compile it. Create a text file named pets10.txt with 10 pets (or use the one below). Store this file in the same folder as your “class” file(s). The format is the same format used in the original homework problem. Each line in the file should contain a pet name (String), a comma, a pet’s age (int) in years, another comma, and a pet’s weight (double) in pounds. Perform the...

  • Registry Java Programming 2) Interface Comparator: The method for comparing two objects is written outside of...

    Registry Java Programming 2) Interface Comparator: The method for comparing two objects is written outside of the class of the objects to be sorted. Several methods can be written for comparing the objects according to different criteria. Specifically, write three classes, DescriptionComparator, FirstOccComparator, and LastOccComparator that implement the interface java.util.Comparator. DescriptionComparator implements the interface Comparator. The method compare compares the description of two objects. It returns a negative value if the description of the first object comes before the description...

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