HCLYYDS 2021-06-14 14:00 采纳率: 100%
浏览 47
已采纳

eclipse java

package bigWork;

public class teachers extends people {
	private course[] courselist=new course[1];
	public teachers(String name) {
		super(name);
		// TODO Auto-generated constructor stub
	}
	public void addcourse(String course){
		(this.courselist[0]).setCourseName(course);;
	}
	@Override
	public String getName() {
		return name;
	}
	public void setName(String name) {
		System.out.println("请输入老师姓名:");
		this.name = name;
	}
	public course[] getCourselist() {
		return courselist;
	}
	public void setCourselist(course[] courselist) {
		this.courselist=courselist;
	}
	public String getcourse(){
		return courselist[0].getCourseName();
	}
}

package bigWork;
import java.util.Scanner;
import java.util.ArrayList;
public class studentandteacherMannager {
		        //创建集合对象,用于存储学生数据
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
				System.out.println("请输入本学期课程(五门课程)");
				System.out.println("课程一:");
				course c1=new course(scanner.nextLine());
				System.out.println("课程二:");
				course c2=new course(scanner.nextLine());
				System.out.println("课程三:");
				course c3=new course(scanner.nextLine());
				System.out.println("课程四:");
				course c4=new course(scanner.nextLine());
				System.out.println("课程五:");
				course c5=new course(scanner.nextLine());
		        ArrayList<students> array1 = new ArrayList<>();
		        ArrayList<teachers> array2 = new ArrayList<>();
		        //用循环完成再次回到主界面
		        while (true) {
		            // 1. 用输出语句完成主界面的编写
		            System.out.println("---------欢迎来到学生老师管理系统------------");
		            System.out.println("1 添加学生和所学科目");
		            System.out.println("2 删除学生");
		            System.out.println("3 查看所有学生和成绩");
		            System.out.println("4 添加老师");
		            System.out.println("5 删除老师");
		            System.out.println("6 查看所有老师和所教科目");
		            System.out.println("7 退出");
		            System.out.println("-------------------------------------");

		            // 2. 用Scanner实现键盘录入数据
		            Scanner s = new Scanner(System.in);
		            int line = s.nextInt();


		            //3. 用switch语句完成操作的选择
		            switch (line) {
		                case 1:
		                    //System.out.println("添加学生");
		                    addstudents(array1);
		                    break;
		                case 2:
		                    //System.out.println("删除学生");
		                    deletestudents(array1);
		                    break;
		                case 3:
		                    //System.out.println("查看所有学生");
		                    findAllstudents(array1);
		                    break;
		                case 4:
		                    //System.out.println("添加老师");
		                    addteachers(array2);
		                    break;
		                case 5:
		                    //System.out.println("删除老师");
		                    deleteteachers(array2);
		                    break;
		                case 6:
		                    //System.out.println("查看所有老师");
		                    findAllteachers(array2);
		                    break;
		                case 7:
		                    System.out.println("谢谢使用");
		                    System.exit(0);
		            }
		        }
		    }
	//查询老师和老师所教科目
		    private static void findAllteachers(ArrayList<teachers> array2) {
					// TODO Auto-generated method stub
		    	for(int i=0;i<array2.size();i++) {
		    	System.out.println("老师姓名:"+array2.get(i).name+"所教科目"+array2.get(i).getcourse());
				}
		    }
			private static void deleteteachers(ArrayList<teachers> array2) {
					// TODO Auto-generated method stub
					Scanner scanner=new Scanner(System.in);
					System.out.println("请输入要删除老师的姓名:");
					String a=scanner.nextLine();
					for(int i=0;i<array2.size();i++) {
						if(array2.get(i).name==a) {
							array2.remove(i);
							System.out.println("删除成功!");
						}else {
							System.out.println("未查询到该老师,删除失败");
						}
					}
				}


			private static void addteachers(ArrayList<teachers> array2) {
				Scanner s=new Scanner(System.in);
		// TODO Auto-generated method stub
					System.out.println("请输入三位老师的姓名:");
					teachers t0=new teachers(s.nextLine());
					teachers t1=new teachers(s.nextLine());
					teachers t2=new teachers(s.nextLine());
					System.out.println("请输入三位老师所教科目:");
					t0.addcourse(s.nextLine());;
					t1.addcourse(s.nextLine());
					t2.addcourse(s.nextLine());
					array2.add(0, t0);
					array2.add(1, t1);
					array2.add(2, t2);
					
	}


			private static void findAllstudents(ArrayList<students> array1) {
					// TODO Auto-generated method stub
					
				}
			//定义一个方法,用于添加学生信息
		    private static void deletestudents(ArrayList<students> array1) {
		// TODO Auto-generated method stub
		
	}


			private static void addstudents(ArrayList<students> array1) {
		// TODO Auto-generated method stub
				Scanner s=new Scanner(System.in);
		// TODO Auto-generated method stub
					System.out.println("请输入五位学生的姓名:");
					students t0=new students(s.nextLine());
					students t1=new students(s.nextLine());
					students t2=new students(s.nextLine());
					students t3=new students(s.nextLine());
					students t4=new students(s.nextLine());
					System.out.println("请输入五位学生所学习的科目(每位学生需要报名三门课):");
					t0.addcourse(s.nextLine(),s.nextLine(),s.nextLine());
					t1.addcourse(s.nextLine(),s.nextLine(),s.nextLine());
					t2.addcourse(s.nextLine(),s.nextLine(),s.nextLine());
					t3.addcourse(s.nextLine(),s.nextLine(),s.nextLine());
					t4.addcourse(s.nextLine(),s.nextLine(),s.nextLine());
					array1.add(0, t0);
					array1.add(1, t1);	
					array1.add(2, t2);
					array1.add(3, t3);
					array1.add(4, t4);
	}
}


这个程序的teachers类里这个setCoursesname出什么错误了?为什么不行啊

  • 写回答

5条回答 默认 最新

  • HCLYYDS 2021-06-14 14:29
    关注
    package bigWork;
    
    public class course {
    	private String courseName;
    	public score[] score;
    	public course(String courseName) {
    		this.courseName = courseName;
    	}
    	public String getCourseName() {
    		return courseName;
    	}
    	public void setCourseName(String courseName) {
    		this.courseName = courseName;
    	}
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 Odoo17操作下面代码的模块时出现没有'读取'来访问
  • ¥50 .net core 并发调用接口问题
  • ¥15 网上各种方法试过了,pip还是无法使用
  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 Hadoop集群部署启动Hadoop时碰到问题
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 QTableWidget重绘程序崩溃
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题