//課程類
public class course {
int id;
String name;
int studyHour;
String teacherName;
String bookName;
//無參構造方法
public course() {}
//有參構造方法
public course(int i, String n, int s, String t, String b) {
this.id = i;
this.name = n;
this.studyHour = s;
this.teacherName = t;
this.bookName = b;
}
//更改器
public void setCourse(int i, String n, int s, String t, String b) {
id = i;
name = n;
studyHour = s;
teacherName = t;
bookName = b;
}
//獲取器
public String toString(){
return "課程編號:" +id + '\t' + "課程名稱:" + name + '\t' + "所需課時:" + studyHour +"課時" + '\t' + "任課教師:" + teacherName + '\t' + "課程書籍:" + bookName;
}
}
//書籍類
public class Tbook {
int bookId;
String bookName;
String author;
double price;
public Tbook(){}
public Tbook(int bookId,String bookName,String author,double price){
this.bookId = bookId;
this.bookName = bookName;
this.author = author;
this.price = price;
}
public void setTook(int bookId,String bookName,String author,double price){
this.bookId = bookId;
this.bookName = bookName;
this.author = author;
this.price = price;
}
public String toString(){
return "書籍編號: " + bookId + '\t' +"書籍名稱:" + bookName +'\t' + "書籍作者:" + author +'\t'+"書籍價格:" + price;
}
}
public class Test {
public static void main(String[] args) {
course p = new course();
p.setCourse(001,"世界與中國", 5, "肖曉明", "中國遊記");
Tbook t = new Tbook();
t.setTook(001, "中國遊記", "肖曉明", 35.8);
System.out.println(p.toString());
System.out.println(t.toString());
}
}