package com.aluracursos.screenmatch.calulate;
import com.aluracursos.screenmatch.models.Movie;
import com.aluracursos.screenmatch.models.Title;
public class TimeCalculator {
private int totalTime;
//aplica polimorfismo es decir usa una
//herramienta para diferentes tareas
public void incluye(Title title){
this.totalTime += title.getDuration();
}
public int getTotalTime() {
return totalTime;
}
}
package com.aluracursos.screenmatch.controllers;
import com.aluracursos.screenmatch.calulate.TimeCalculator;
import com.aluracursos.screenmatch.models.Movie;
import com.aluracursos.screenmatch.models.Serie;
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {
TimeCalculator timeCalculator = new TimeCalculator();
Movie movie1 = new Movie(); //Llamo a la instancia
movie1.setTitle("ENCANTO");
movie1.setYear(2022);
movie1.setDuration(65);
System.out.println(movie1.toString());
Movie movie2 = new Movie(); //Llamo a la instancia
movie2.setTitle("MATRIX");
movie2.setYear(1999);
movie2.setDuration(90);
System.out.println(movie2.toString()); //llamo el menu
System.out.println(movie1.evaluation(10)); //LLamo metodo que suma las evaluacioness
System.out.println(movie1.evaluation(10));
System.out.println(movie1.getTotalEvaluations());
System.out.println("MEDIA "+movie1.calculateAverage());
Serie casaDragon = new Serie();
casaDragon.setTitle("La casa del dragon");
casaDragon.setYear(2022);
casaDragon.setTemporadas(1);
casaDragon.setMinutesPerEpisode(50);
casaDragon.setEpisodesSeason(10);
System.out.println(casaDragon.getDuration());
System.out.println(casaDragon.toString());
timeCalculator.incluye(movie1);
timeCalculator.incluye(casaDragon);
timeCalculator.incluye(movie2);
System.out.println(" TIEMPO TOTAL "+timeCalculator.getTotalTime());
}
}
package com.aluracursos.screenmatch.models;
public class Serie extends Title {
private int temporadas;
private int episodesSeason;
private int minutesPerEpisode;
//Vamos a sobrescribir el metodo
//estableciendo comportamientos diferente
@Override
public int getDuration() {
return episodesSeason* minutesPerEpisode * temporadas;
}
public int getTemporadas() {
return temporadas;
}
public void setTemporadas(int temporadas) {
this.temporadas = temporadas;
}
public int getEpisodesSeason() {
return episodesSeason;
}
public void setEpisodesSeason(int episodesSeason) {
this.episodesSeason = episodesSeason;
}
public int getMinutesPerEpisode() {
return minutesPerEpisode;
}
public void setMinutesPerEpisode(int minutesPerEpisode) {
this.minutesPerEpisode = minutesPerEpisode;
}
}
package com.aluracursos.screenmatch.models;
public class Title {
private String title;
private int year;
private int duration;
private boolean included;
private double sumEvaluation;
private int totalEvaluations;
@Override /*Metodo crear ficha tecnica*/
public String toString() {
return "The name of the movie is "+title+"\t"+year+"\t"+getDuration()+"\t"+included;
}
/*Metodo para evaluar */
public double evaluation (double nota){
totalEvaluations++;
return sumEvaluation+=nota;
}
/*Metodo para calcular media */
public double calculateAverage(){
return sumEvaluation/totalEvaluations;
}
public int getTotalEvaluations() {
return totalEvaluations;
}
public void setTotalEvaluations(int totalEvaluations) {
this.totalEvaluations = totalEvaluations;
}
public double getSumEvaluation() {
return sumEvaluation;
}
public void setSumEvaluation(double sumEvaluation) {
this.sumEvaluation = sumEvaluation;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public int getDuration() {
return duration;
}
public void setDuration(int duration) {
this.duration = duration;
}
public boolean isIncluded() {
return included;
}
public void setIncluded(boolean included) {
this.included = included;
}
}