You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
2.7 KiB
111 lines
2.7 KiB
|
|
import java.io.IOException;
|
|
import java.io.FileWriter;
|
|
import java.io.File;
|
|
import java.util.Scanner;
|
|
import java.io.FileNotFoundException;
|
|
import java.util.ArrayList;
|
|
|
|
public class Database {
|
|
|
|
public static boolean userExists(String username)
|
|
{
|
|
boolean found = false;
|
|
|
|
try {
|
|
File filex=new File("c:\\tmp\\FavoriteMovies\\files\\login_cred.txt");
|
|
Scanner scan;
|
|
scan = new Scanner(filex);
|
|
|
|
scan.useDelimiter("[\n]");
|
|
|
|
|
|
if(scan.hasNext() && !found ) {
|
|
|
|
String line_ = scan.nextLine();
|
|
|
|
if(line_.equals(username))
|
|
found = true;
|
|
}
|
|
scan.close();
|
|
}
|
|
catch (FileNotFoundException e1) {
|
|
// TODO Auto-generated catch block
|
|
e1.printStackTrace();
|
|
}
|
|
|
|
return found;
|
|
}
|
|
|
|
public static void addMovie(Movie m){
|
|
try {
|
|
|
|
FileWriter fw = new FileWriter( "C:\\Users\\skc\\eclipse-workspace\\first\\Favorite_Movies\\src\\files\\data.txt",true);
|
|
fw.write(m.getMovieId());
|
|
|
|
fw.append(" ").write(m.getTitle());
|
|
|
|
fw.append(" ").write(m.getYear());
|
|
|
|
fw.append(" ").write(m.getLength());
|
|
|
|
fw.append(" ").write(m.getGenre());
|
|
|
|
fw.append(" ").write(m.getStudioName());
|
|
|
|
fw.append(" ").write(m.getProducerName());
|
|
|
|
fw.append(" ").write(m.getShortDescription());
|
|
|
|
fw.append(" ").write(String.valueOf(m.getAvgRating()));
|
|
|
|
fw.append(" ").write(m.getNumWatched());
|
|
|
|
fw.write("\n");
|
|
|
|
fw.close();
|
|
|
|
}
|
|
catch (IOException e1) { // TODO Auto-generated catch block
|
|
e1.printStackTrace();
|
|
}
|
|
|
|
}
|
|
|
|
public static void addStar(Star s)
|
|
{
|
|
|
|
}
|
|
|
|
public static void addRating(Rating r)
|
|
{
|
|
|
|
}
|
|
|
|
public static int findMovieId(String title)
|
|
{
|
|
// TODO 6: search all titles and find matching movie id , return 0 if not found
|
|
return 1;
|
|
}
|
|
|
|
public static void incNumWatched(int movieId)
|
|
{
|
|
// TODO 7: find movie by id and increment numWatched by 1
|
|
}
|
|
|
|
public static Movie findTopMovieByGenre(String genre)
|
|
{
|
|
Movie m = new Movie();
|
|
// TODO 8: search all movies by genre, and find the one with the top rating and return it
|
|
return m;
|
|
}
|
|
|
|
public static ArrayList<Movie> findMoviesForStar(String starName)
|
|
{
|
|
|
|
ArrayList<Movie> list = new ArrayList<Movie>();
|
|
// TODO 9: search all movies in which the star has acted and return a list
|
|
return list;
|
|
}
|
|
|
|
}
|