package hello;
import java.util.Scanner;
class Student{
private Course1 []course;
private String name;
private int courseNum=0;
Student(){}
void Insert()
{
System.out.println(this.name+"同学一共选课"+this.courseNum+"门,"+"请输入要选的科目:");
this.course=new Course1[this.courseNum];
for(int i=0;i<this.courseNum;++i){
String c;
Scanner scan=new Scanner(System.in);
c=scan.next();
Course1 C=new Course1();
C.setCourse(c);
this.course[i]=C;
scan.close();
}
}
public int getCourseNum() {
return courseNum;
}
public void setCourseNum(int courseNum) {
this.courseNum = courseNum;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
void Print()
{
System.out.println(this.name+"同学"+"一共选择了"+this.courseNum+"课程,课程列表如下:");
for(int i=0;i<this.courseNum;++i){
System.out.println(course[i]);
}
}
}
class Course1{
private Student []student;
private int studentNum=0;
private String course;
public int getStudentNum() {
return studentNum;
}
public void setStudentNum(int studentNum) {
this.studentNum = studentNum;
}
void insert()
{
setStudent(new Student[this.studentNum]);
for(int i=0;i<this.studentNum;++i){
Student s=new Student();
Scanner in =new Scanner(System.in);
String name;
name=in.toString();
s.setName(name);
in.close();
}
}
public String getCourse() {
return course;
}
public void setCourse(String course) {
this.course = course;
}
public Student [] getStudent() {
return student;
}
public void setStudent(Student [] student) {
this.student = student;
}
}
public class Course {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
Student student=new Student();
System.out.println("请输入学生的姓名:");
String name;
name=in.next();
student.setName(name);
System.out.println("请输入课程的数量:");
int CourseNum;
CourseNum=in.nextInt();
student.setCourseNum(CourseNum);
student.Insert();
student.Print();
in.close();
}
}
为完成的JAVA 学生与课程类
最新推荐文章于 2021-03-15 10:13:01 发布