Student Course Book

Create classes named Book, Course and Student to perform simple course-selecting system (CSS). Student has at least three overloaded constructors with different parameter list. Student may select one or more Course, and one Course also has some members of Book.

Examples:

 

import java.util.List;
import java.util.ArrayList;
//import java.util.Iterator;
public class CSS {
	public static void main(String[] args) {
		ArrayList<String> k = new ArrayList();
		int n = args.length;
		if(n == 0)
			return ;
		for(int i = 0; i < args.length; i++)
			if(i != 0)
				k.add(args[i]);
		Student now = new Student(args[0], k);
		now.print();
	}
class Student{
	public String sid;
	  public String sname;
	  public List<Course> courses;
	  public Student() {
		  
	  }
	  public Student(String sid,ArrayList<String> cs){
	    this.sid=sid;
	    courses=new ArrayList();
	    for(String i:cs)
	    	courses.add(new Course(i));
	   
	    //System.out.println(this.sid+"select"+this.courses+"with book");
	  }
	  public Student(String sid,String sname,List<Course> courses) {
		  this.sid=sid;
		  this.sname=sname;
		  this.courses=courses;
	  }
	  public String getSname() {
		  return sname;
	  }
	  public void setSname(String s) {
		  this.sname=s;
	  }
	  public String getSid() {
		  return this.sid;
	  }
	  public void setSid(String s) {
		  this.sid=s;
	  }
	  public List<Course> getCourses(){
		  return courses;
	  }
	  public void setCourses(List<Course> s) {
		  this.courses=s;
	  }
		public void print(){
			System.out.print(sid);
			if(!courses.isEmpty()){
				System.out.print(" select ");
				for(int i = 0; i < courses.size(); i++){
					if(i != 0)
						System.out.print("; ");
					courses.get(i).print();
				}
			}
			System.out.print(".");
		}
	}

class Course{
	public String cname;
	public List<Book> books;
	public Course() {
	}
	public Course(String cname,List<Book> books) {
		this.cname=cname;
		this.books=books;
	}
	public Course(String cname) {
		this.cname=cname;
	}
	public String getCname() {
		return this.cname;
	}
	public void setCname(String s) {
		this.cname=s;
	}
	public List<Book> getBooks(){
		return this.books;
	}
	public void setBooks(List<Book> b) {
		this.books=b;
	}
	public void print(){
		System.out.print(cname);
		if(!books.isEmpty()){
			System.out.print(" with ");
			for(int i = 0; i < books.size(); i++){
				if(i != 0)
					System.out.print(", ");
				books.get(i).print();
			}

		}
	}
}
class Book{
	public String bname;
	public Book() {
		
	}
	public Book(String s) {
		this.bname=s;
	}
	public String getBname() {
		return this.bname;
	}
	public void setBname(String s) {
		this.bname=s;
	}
	void print(){
		System.out.print(bname);
	}
}

}
> java CSS 16131001 Java
  16131001 select Java with books Thinking in Java, Java 8
  
> java CSS 16131001 Java WebEngineering
  16131001 select Java with books Thinkin in java
  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值