在我的任务中创建方法时出现问题

use*_*787 1 java methods class

目标是产生这个:

这里的任务摘要图片

这些是我尝试编译时遇到的错误: 屏幕截图

我已经改变并修复了我认为哪些更明显的错误,这些错误主要是我的愚蠢.抱歉.

我有这个代码

public class Ex5Program {

public void start() {
    Tutor[] tutors = createTutorsArray();
    printTutors(tutors);
    printOnLeaveList(tutors);
    updateTutorDetails(tutors[1]);
    printNewTutorDetails(tutors[1]);
    Tutor tutorWithMostPapers = getTutorWithMostPapers(tutors);
    printTutorWithMostPapers(tutorWithMostPapers);
}

private Tutor[] createTutorsArray() {
    String[] noPapers = {};
    String[] introductoryPapers = {"CompSci101", "CompSci111"};
    String[] coreStage1Papers = {"CompSci101", "CompSci105"};
    String[] allStageOnePapers = {"CompSci111", "CompSci101", "CompSci105"};
    String[] stageTwoPapers = {"CompSci210", "CompSci220", "CompSci225", "CompSci230"};
    Tutor[] tutors = new Tutor[7];
    tutors[5] = new Tutor("Sad Sack", 86302, introductoryPapers, false);
    tutors[4] = new Tutor("Crystal Ball", 49123, introductoryPapers, false);
    tutors[2] = new Tutor("Earl Lee Riser", 40879, allStageOnePapers, true);
    tutors[3] = new Tutor("Tom Katt", 50876, stageTwoPapers, false);
    tutors[1] = new Tutor("Candy Kane", 30869, noPapers, false);
    tutors[0] = new Tutor("Carrie Oakey", 30987, coreStage1Papers, true);
    tutors[6] = new Tutor("Sonny Day", 49586, stageTwoPapers, true);
    return tutors;
}

private void printTutors(Tutor[] tutors) {
    System.out.println("Current Tutors");
    System.out.println("==============");
    for (int i = 0; i < tutors.length; i++) {
        System.out.print(i + 1 + ". ");
        System.out.println(tutors[i].toString());
    }
}

private void printOnLeaveList(Tutor[] tutors) {
    System.out.println();
    System.out.println("Tutors Currently on Leave");
    System.out.println("=========================");
    for (int i = 0; i < tutors.length; i++) {
        if (tutors[i].isOnLeave()) {
            System.out.println(tutors[i].getName());
        }
    }
}


private void updateTutorDetails(Tutor tutor) {
    tutor.setName("Ali Katt");
    tutor.setStaffId(23456);
    String[] stage1Papers = {"CompSci101", "CompSci105", "CompSci111"};
    tutor.setPapers(stage1Papers);
    tutor.setOnLeave(true);
}

private void printNewTutorDetails(Tutor tutor) {
    System.out.println();
    System.out.println("Updated details");
    System.out.println("===============");
    System.out.println("Name: " + tutor.getName());
    System.out.println("Id: " + tutor.getStaffId());
    String[] papers = tutor.getPapers();
    System.out.print("Papers: ");
    if (papers.length > 0) {
        for (int i = 0; i < papers.length; i++) {
            System.out.print(papers[i] + " ");
        }
    } else {
        System.out.print("None");
    }
    System.out.println();
    if (tutor.isOnLeave()) {
        System.out.println("Currently on leave");
    }
}

private Tutor getTutorWithMostPapers(Tutor[] tutors) {
    Tutor tutorWithMostPapersSoFar = tutors[0];
    for (int i = 0; i < tutors.length; i++) {
        if (tutors[i].teachesMorePapersThan(tutorWithMostPapersSoFar)) {
            tutorWithMostPapersSoFar = tutors[i];
        }
    }
    return tutorWithMostPapersSoFar;
}

private void printTutorWithMostPapers(Tutor tutorWithMostPapers) {
    System.out.println();
    System.out.println("Most papers");
    System.out.println("===========");
    System.out.println(tutorWithMostPapers.getName() + " teaches more papers than any other tutor.");
}

}
Run Code Online (Sandbox Code Playgroud)

我在这里创建了这个代码(它已被更改):

public class Tutor {

// instance variables

private String name;
private int staffId;
private String[] papers;
private boolean onLeave;

public Tutor(String name, int staffId, String[] papers, boolean onLeave) {
    // Complete this constructor method
    this.name = name;
    this.staffId = staffId;
    this.papers = papers;
    this.onLeave = onLeave;
}
// Insert getName() method here
public String getName(){
    return name;
}
// Insert setName() method here
public void setName(String name){
    this.name = name;
}
// Insert getStaffId() method here
public int getStaff(){
    return staffId;
}
// Insert setStaffId() method here
public void setStaffId(int StaffId){
    this.staffId = staffId;
}
// Insert getPapers() method here;
public  String[] getPapers(){
    return papers;
}
// Insert setPapers() method here
public void setPapers(String[] papers){
    this.papers = papers;
}
// Insert isOnLeave() method here
public boolean isOnLeave(){
    return onLeave;
}
// Insert setOnLeave() method here
public void setOnLeave(boolean OnLeave){
    this.onLeave = onLeave;
}
// Insert toString() method here
public String toString(){
    return name + "(Staff id:"+staffId+")";
}
// Insert teachesMorePapersThan() method here
public Tutor teachesMorePapersThan(Tutor other){
    return(papers.length>other.papers.length);
}
}
Run Code Online (Sandbox Code Playgroud)

hmj*_*mjd 5

错字:toString()不是tostring(),导致Object.toString()调用,并且没有返回预期的格式化字符串.改成:

@Override public String toString()
Run Code Online (Sandbox Code Playgroud)

@Overridetostring()作为方法名称的情况下使用注释会产生编译器错误并提醒您错误,因为超类中不存在该名称的方法.

一些setter方法缺少参数:

// Insert setPapers() method here
public void setPapers(){
    this.papers = papers;
}

// Insert setOnLeave() method here
public void setOnLeave(){
    this.OnLeave = OnLeave;
}
Run Code Online (Sandbox Code Playgroud)