Java打造CD、DVD数据库
程序员文章站
2022-05-08 11:06:02
...
Written by Bruth_Lee in Southwest University of Science And Technology.
Basic operations like this、、、
像这样的基本操作、、、、、
My code is not written in a file,but you can synthesize it.
(我的代码没有写到一个文件里面,但是你可以合成)
接下来,上菜刀、、、
package notepad;
import java.util.ArrayList;
public class Database {
ArrayList<CD> listCD = new ArrayList<CD>();
ArrayList<DVD> listDVD = new ArrayList<DVD>();
public void add(CD cd) {
listCD.add(cd);
}
public void add(DVD dvd) {
listDVD.add(dvd);
}
public void list() {
for(CD cd : listCD) {
cd.print();
}
System.out.println("This are my favourite films :");
System.out.println();
for(DVD dvd : listDVD) {
dvd.print();
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Written by Bruth_Lee in Southwest University of Science And Technology.");
System.out.println("This are my favourite songs :");
System.out.println();
Database db = new Database();
db.add(new CD("Carrie", "Tan_xuanyuan", 17, 4, "Very good!"));
db.add(new CD("告别的时代","Tan_xuanyuan",17,3,"Xuanyuan , I love you!"));
db.add(new CD("青花瓷","Jay_Zhou",17,3,"地表最强!"));
db.add(new DVD("战狼2","吴京",60,"He is a hero!"));
db.add(new DVD("前任3","不详",60,"看的我心痛!"));
db.list();
}
}
CD类
package notepad;
public class CD {
private String title;
private String artist;
private int numofTracks;
private int playingtime;
private boolean GotIt;
private String comment;
public CD(String title, String artist, int numofTracks, int playingtime, String comment) {
super();
this.title = title;
this.artist = artist;
this.numofTracks = numofTracks;
this.playingtime = playingtime;
this.comment = comment;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public void print() {
// TODO Auto-generated method stub
System.out.println("Title : "+title+" "+"Artist : "+artist);
System.out.println("Comment :"+comment);
System.out.println();
}
}
DVD类
package notepad;
public class DVD {
private String title;
private String director;
private int length;
private String comment;
public DVD(String title, String director, int length, String comment) {
super();
this.title = title;
this.director = director;
this.length = length;
this.comment = comment;
}
public void print() {
System.out.println("Title : "+title+" "+"Director : "+director+" : "+"lenth : "+length);
System.out.println("Comment : "+comment);
System.out.println();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
上一篇: 莫比乌斯反演·学习记录
下一篇: DVD出租系统【3】MFC界面连接数据库
推荐阅读