actor has name, year of birth, and number of movie he/she starred in. A Movie ha
ID: 3703391 • Letter: A
Question
actor has name, year of birth, and number of movie he/she starred in. A Movie has tie, supporting actor a Write Java classes for Actor and Movie per the UML diagram below and according to the to the following Include only attributes/methods/constructors that are in the UML diagram only. For the class Movie: .If the star of movie is reset to a new actor, the11.mage0- For the Actor class: Two movies objects are the same if they have the name. strie starCount of the new actor is incremented and the torine count must be decremented for the old actor - The string representation of an Actor object must be in the format: fnome of actori year of birth) Write your code here: public class.Explanation / Answer
Given below is the code according to the specifications in the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you
public class Actor {
private String name;
private int year;
public int starCount;
public Actor(String name, int year)
{
this.name = name;
this.year = year;
}
public String getName()
{
return name;
}
public int getAge()
{
return 2018 - year;
}
public String toString()
{
return "{" + name + "; " + year + "}";
}
}
public class Movie {
private Actor star;
public Actor support;
public String title;
public Movie(String title)
{
this.title = title;
}
public Movie(Movie other)
{
star = other.star;
support = other.support;
title = other.title;
}
public void setStar(Actor a)
{
if(star != null)
{
star.starCount--;
}
star = a;
star.starCount++;
}
public Actor getStar()
{
return star;
}
public boolean equals(Object o)
{
if(o instanceof Movie)
{
if(((Movie)o).title.equals(title))
return true;
}
return false; //if o is not Movie object or titles don't match
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.