Question

Write a program that takes a .txt file with movie details. First entry is the year...

Write a program that takes a .txt file with movie details. First entry is the year of the movie, second is the name of the movie, third is the name of the actor and fourth is the rating of the genre of the movie. These are all seperated by a period. Need to have features, searching the movie based on the title of the movie, year of movie and genre of the movie. (need to have classes for the features) IN JAVA. Also need a feature that will add the movie to cart. Can only add 3 movies.

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

Code:

====

package com.abc.expert;

import java.io.File;

import java.io.FileNotFoundException;

import java.util.ArrayList;

import java.util.Iterator;

import java.util.Scanner;

public class MovieProject {

public static void main(String[] args) throws FileNotFoundException {

Authentication auth = new Authentication();

int counter = 1;

Scanner sc = new Scanner(System.in);

System.out.print("Enter username: ");

String username = "", password = "";

username = sc.nextLine();

System.out.print("Enter password: ");

password = sc.nextLine();

if(auth.login(username, password)){

System.out.println("Welcome!!!\n\n");

while(true){

System.out.print("1 - Search by movie name \n2 - Search by genre\n3 - Enter a new movie\n4 - Quit \nEnter your choice (1/2/3/4): ");

String choice = sc.nextLine();

ArrayList<String> movies = Database.getDatabse();

if(choice.equals("1")){

Iterator<String> it = movies.iterator();

System.out.print("\nEnter name of the movie: ");

String movieName = sc.nextLine();

while(it.hasNext()){

String rec = it.next();

//System.out.println(rec);

if(rec.split("\\.")[1].equalsIgnoreCase(movieName)){

System.out.println("Movie year: "+rec.split("\\.")[0]);

System.out.println("Movie Name: "+rec.split("\\.")[1]);

System.out.println("Movie actor: "+rec.split("\\.")[2]);

System.out.println("Movie genre: "+rec.split("\\.")[3]);

System.out.println("\n");

}

}

}

else if(choice.equals("2")){

Iterator<String> it = movies.iterator();

System.out.print("Enter genre of the movie: ");

String movieGenre = sc.nextLine();

while(it.hasNext()){

String rec = it.next();

if(rec.split("\\.")[3].equalsIgnoreCase(movieGenre)){

System.out.println("Movie year: "+rec.split("\\.")[0]);

System.out.println("Movie Name: "+rec.split("\\.")[1]);

System.out.println("Movie actor: "+rec.split("\\.")[2]);

System.out.println("Movie genre: "+rec.split("\\.")[3]);

System.out.println("\n");

}

}

}

else if(choice.equals("3")) {

if(counter<=3) {

System.out.print("Enter a movie year,name,actor,genre with comma separated: ");

String record = sc.nextLine();

Database.addMovie(record);

counter++;

}

else {

System.out.println("Three new movies were already added..");

}

}

else if(choice.equals("4")){

System.out.println("Good bye!!!");

break;

}

else{

System.out.println("Invalid choice!!!");

}

}

}

else{

System.out.println("Invalid credentials!!!");

}

}

}

class Authentication{

private String username = "admin", password = "admin@123";

public boolean login(String username, String passowrd){

if(username.equals(this.username) && passowrd.equals(this.password)){

return true;

}

else{

return false;

}

}

}

class Database{

private static ArrayList<String> movies = new ArrayList<String>();

public static ArrayList<String> getDatabse() throws FileNotFoundException{

File file = new File("input.txt");

Scanner sc = new Scanner(file);

while(sc.hasNext()){

movies.add(sc.next());

}

return movies;

}

public static void addMovie(String record) {

movies.add(record);

}

}

Output screen:

============

Add a comment
Know the answer?
Add Answer to:
Write a program that takes a .txt file with movie details. First entry is the year...
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
  • LAB 7-Movie List Program Goali Your assignment is to write a C++program to implement the ADT...

    LAB 7-Movie List Program Goali Your assignment is to write a C++program to implement the ADT List by creating a list of movies. This assignment will help you practice: multiple file programming, classes, pablic and private methods, dynamie memory, constructors and destructors, arrays and files Implementation the required classes This lab assignment gives you the opportunity to practice creating classes and using dynamic memory in one of There are two classes to implement: Movie and MovieList. As you can see...

  • Need help for C program. Thx #include <stdio.h> #include <string.h> #include <ctype.h> // READ BEFORE YOU...

    Need help for C program. Thx #include <stdio.h> #include <string.h> #include <ctype.h> // READ BEFORE YOU START: // This homework is built on homework 06. The given program is an updated version of hw06 solution. It begins by displaying a menu to the user // with the add() function from the last homework, as well as some new options: add an actor/actress to a movie, display a list of movies for // an actor/actress, delete all movies, display all movies,...

  • C++ Write a C++ program that user is able to choose the function of their wanting from this menu : Users will be asked...

    C++ Write a C++ program that user is able to choose the function of their wanting from this menu : Users will be asked to enter the movies they like along with the Genre and one Actor/Actress per movie. the entering process should look like this: Note that if the user enters yes, the program should start entering the next movie with its properties. Available movies must be entered as follow: The program should enter as many available movies as...

  • Using an object-oriented approach, write a program to read a file containing movie data (Tile, Director,...

    Using an object-oriented approach, write a program to read a file containing movie data (Tile, Director, Genre, Year Released, Running Time) into a vector of structures and perform the following operations: Search for a specific title Search for movies by a specific director Search for movies by a specific genre Search for movies released in a certain time period Search for movies within a range for running time Display the movies on the screen in a nice, easy to read...

  • WONT COMPILE ERROR STRAY / TEXT.H AND CPP PROGRAM SAYING NOT DECLARED HAVE A DRIVER WILL...

    WONT COMPILE ERROR STRAY / TEXT.H AND CPP PROGRAM SAYING NOT DECLARED HAVE A DRIVER WILL PASTE AT BOTTOM MOVIES.CPP #include "movies.h" #include "Movie.h" Movies *Movies::createMovies(int max) { //dynamically create a new Movies structure Movies *myMovies = new Movies; myMovies->maxMovies = max; myMovies->numMovies = 0; //dynamically create the array that will hold the movies myMovies->moviesArray = new Movie *[max]; return myMovies; } void Movies::resizeMovieArray() { int max = maxMovies * 2; //increase size by 2 //make an array that is...

  • Write a Java program to read customer details from an input text file corresponding to problem...

    Write a Java program to read customer details from an input text file corresponding to problem under PA07/Q1, Movie Ticketing System The input text file i.e. customers.txt has customer details in the following format: A sample data line is provided below. “John Doe”, 1234, “Movie 1”, 12.99, 1.99, 2.15, 13.99 Customer Name Member ID Movie Name Ticket Cost Total Discount Sales Tax Net Movie Ticket Cost Note: if a customer is non-member, then the corresponding memberID field is empty in...

  • In C++ write a simple menu program that displays a menu for the user in an...

    In C++ write a simple menu program that displays a menu for the user in an object-oriented technique. The menu should keep showing up until the user chooses to quit. Also, there is a sub-menu inside a menu. The user should get at least a line displayed after he or she chooses that particular option meaning if the user presses 1 for the read actors from the file. The output can look like "reading actors from a file" and then...

  • Need a program in python. Asterix and Obelix want to store and process information about movies...

    Need a program in python. Asterix and Obelix want to store and process information about movies they are interested in. So, you have been commissioned to write a program in Python to automate this. Since they are not very computer literate, your program must be easy for them to use. They want to store the information in a comma separated text file. Using this they would need to generate a report – see all items AND show a bar chart...

  • 1. write a java program using trees(binary search treee) to read integers from input file( .txt)...

    1. write a java program using trees(binary search treee) to read integers from input file( .txt) and add +1 to each number that you read from the input file. then copy result to another (.txt) file. example: if inpu File has numbers like 4787 79434 4326576 65997 4354 the output file must have result of 4788 79435 4326577 65998 4355 Note: there is no commas in between the numbers. dont give images or theory please.

  • Write a program that takes a file as input and checks whether or not the content...

    Write a program that takes a file as input and checks whether or not the content of the file is balanced. In the context of this assignment “balanced” means that your program will check to make sure that for each left bracket there is a closing right bracket. Examples:             [ ( ) ] { } à balanced.             [ ( ] ) { } à unbalanced. Here is the list of brackets/braces that program must support: (: left parentheses...

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