//课程类
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());
}
}