在线求助啊,不是搞java的,就是帮忙写个类!!!在线等。。。100分
就是写个电影类吧,在写个主函数测试一下
[解决办法]
public class Movie {
private String name;
private String MPAA;
private int terrible;
private int bad;
private int ok;
private int good;
private int great;
public Movie(String name, String mPAA) {
super();
this.name = name;
MPAA = mPAA;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMPAA() {
return MPAA;
}
public void setMPAA(String mPAA) {
MPAA = mPAA;
}
public int getTerrible() {
return terrible;
}
public void setTerrible(int terrible) {
this.terrible = terrible;
}
public int getBad() {
return bad;
}
public void setBad(int bad) {
this.bad = bad;
}
public int getOk() {
return ok;
}
public void setOk(int ok) {
this.ok = ok;
}
public int getGood() {
return good;
}
public void setGood(int good) {
this.good = good;
}
public int getGreat() {
return great;
}
public void setGreat(int great) {
this.great = great;
}
public void addRating(int rate) {
switch (rate) {
case 1:
this.terrible++;
break;
case 2:
this.bad++;
break;
case 3:
this.ok++;
break;
case 4:
this.good++;
break;
case 5:
this.great++;
break;
default:
System.out.println("wrong rate!!!");
break;
}
}
public float getAverage() {
return (float) (terrible + 2 * bad + 3 * ok + 4 * good + 5 * great) / (15);
}
public static void main(String[] args) {
Movie movie1 = new Movie("终结者", "R");
Movie movie2 = new Movie("敢死队", "R");
movie1.addRating(1);
movie1.addRating(2);
movie1.addRating(3);
movie1.addRating(3);
movie1.addRating(4);
movie1.addRating(5);
movie1.addRating(5);
movie1.addRating(5);
movie1.addRating(5);
movie2.addRating(1);
movie2.addRating(2);
movie2.addRating(3);
movie2.addRating(3);
movie2.addRating(4);
movie2.addRating(4);
movie2.addRating(4);
movie2.addRating(4);
movie2.addRating(5);
movie2.addRating(5);
movie2.addRating(5);
System.out.println("movie1 " + "电影名:" + movie1.getName() + " MPAA:"
+ movie1.getMPAA() + " 平均得分:" + movie1.getAverage());
System.out.println("movie2 " + "电影名:" + movie2.getName() + " MPAA:"
+ movie2.getMPAA() + " 平均得分:" + movie2.getAverage());
}
}
public float getAverage() {
return (float) (terrible + 2 * bad + 3 * ok + 4 * good + 5 * great) / (terrible + bad + ok + good + great);
}