4 changed files with 64 additions and 0 deletions
@ -0,0 +1,13 @@ |
|||||
|
public class AnimatedMovie extends Movie { |
||||
|
private String animationStudio; |
||||
|
|
||||
|
public AnimatedMovie(String title, int year, double rating, String genre, String animationStudio) { |
||||
|
super(title, year, rating, genre); |
||||
|
this.animationStudio = animationStudio; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void play() { |
||||
|
System.out.println("动画电影,制作公司:" + animationStudio); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
public abstract class Movie { |
||||
|
private String title; |
||||
|
private int year; |
||||
|
private double rating; |
||||
|
private String genre; |
||||
|
|
||||
|
public Movie() {} |
||||
|
|
||||
|
public Movie(String title, int year, double rating, String genre) { |
||||
|
this.title = title; |
||||
|
this.year = year; |
||||
|
this.rating = rating; |
||||
|
this.genre = genre; |
||||
|
} |
||||
|
|
||||
|
// 抽象方法:由不同类型的电影自己实现播放逻辑
|
||||
|
public abstract void play(); |
||||
|
|
||||
|
// getter & setter
|
||||
|
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 double getRating() { return rating; } |
||||
|
public void setRating(double rating) { this.rating = rating; } |
||||
|
public String getGenre() { return genre; } |
||||
|
public void setGenre(String genre) { this.genre = genre; } |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
public class Test { |
||||
|
public static void main(String[] args) { |
||||
|
Movie m1 = new TheatreMovie("流浪地球", 2023, 9.0, "科幻", 58.0); |
||||
|
Movie m2 = new AnimatedMovie("哪吒", 2019, 9.5, "动画", "可可豆"); |
||||
|
|
||||
|
m1.play(); |
||||
|
m2.play(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,13 @@ |
|||||
|
public class TheatreMovie extends Movie { |
||||
|
private double ticketPrice; |
||||
|
|
||||
|
public TheatreMovie(String title, int year, double rating, String genre, double ticketPrice) { |
||||
|
super(title, year, rating, genre); |
||||
|
this.ticketPrice = ticketPrice; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void play() { |
||||
|
System.out.println("在电影院播放,票价:" + ticketPrice); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue