设计一个基于java的电影类
时间: 2024-10-07 19:05:39 浏览: 23
设计一个基于Java的电影类,通常会包含一些基本属性,如电影名(title)、导演(director)、演员列表(actors)、上映年份(releaseYear),以及可能的一些额外信息,比如剧情简介(summary)、评分(rating)等。以下是这个类的一个简单实现:
```java
public class Movie {
private String title;
private String director;
private List<String> actors;
private int releaseYear;
private String summary;
private double rating;
// 构造函数
public Movie(String title, String director, List<String> actors, int releaseYear, String summary, double rating) {
this.title = title;
this.director = director;
this.actors = actors;
this.releaseYear = releaseYear;
this.summary = summary;
this.rating = rating;
}
// 获取和设置属性的方法
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDirector() {
return director;
}
public void setDirector(String director) {
this.director = director;
}
public List<String> getActors() {
return actors;
}
public void setActors(List<String> actors) {
this.actors = actors;
}
public int getReleaseYear() {
return releaseYear;
}
public void setReleaseYear(int releaseYear) {
this.releaseYear = releaseYear;
}
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public double getRating() {
return rating;
}
public void setRating(double rating) {
this.rating = rating;
}
// 其他方法,如toString()用于返回类的描述字符串
@Override
public String toString() {
return "Movie{" +
"title='" + title + '\'' +
", director='" + director + '\'' +
", actors=" + actors +
", releaseYear=" + releaseYear +
", summary='" + summary + '\'' +
", rating=" + rating +
'}';
}
}
```
阅读全文