用java设计一个可以运行的电影类
时间: 2024-10-07 18:05:39 浏览: 23
基于Java的电影院订票管理系统设计源码
5星 · 资源好评率100%
在Java中设计一个简单的电影类,我们通常会包含一些基本属性如电影名、导演、演员、上映日期等,并提供一些常用的方法,如播放、暂停、停止等。这里是一个基础版的`Movie`类示例:
```java
public class Movie {
private String title;
private String director;
private String[] actors;
private Date releaseDate;
private boolean isPlaying;
// 构造函数
public Movie(String title, String director, String[] actors, Date releaseDate) {
this.title = title;
this.director = director;
this.actors = actors;
this.releaseDate = releaseDate;
this.isPlaying = false;
}
// 获取和设置方法
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 String[] getActors() { return actors; }
public void setActors(String[] actors) { this.actors = actors; }
public Date getReleaseDate() { return releaseDate; }
public void setReleaseDate(Date releaseDate) { this.releaseDate = releaseDate; }
public boolean isPlaying() { return isPlaying; }
public void setPlaying(boolean playing) { this.isPlaying = playing; }
// 模拟播放、暂停和停止方法
public void play() {
if (!isPlaying) {
System.out.println(title + "开始播放");
isPlaying = true;
} else {
System.out.println(title + "已正在播放");
}
}
public void pause() {
if (isPlaying) {
System.out.println(title + "暂停");
isPlaying = false;
} else {
System.out.println(title + "已经暂停");
}
}
public void stop() {
System.out.println(title + "停止");
isPlaying = false;
}
}
阅读全文