为什么这个Collections.sort没有构建?

时间:2018-02-01 16:41:16

标签: java sorting arraylist

This is the build error I get

package quarterback;

public class Quarterback {

    private String name;
    private int numberOfSuperBowlsWon;
    private int careerPassingYards;
    private int careerPassingTouchdowns;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getNumberOfSuperBowlsWon() {
        return numberOfSuperBowlsWon;
    }
    public void setNumberOfSuperBowlsWon(int numberOfSuperBowlsWon) {
        this.numberOfSuperBowlsWon = numberOfSuperBowlsWon;
    }
    public int getCareerPassingYards() {
        return careerPassingYards;
    }
    public void setCareerPassingYards(int careerPassingYards) {
        this.careerPassingYards = careerPassingYards;
    }
    public int getCareerPassingTouchdowns() {
        return careerPassingTouchdowns;
    }
    public void setCareerPassingTouchdowns(int careerPassingTouchdowns) {
        this.careerPassingTouchdowns = careerPassingTouchdowns;
    }
    // Add a constructor that takes name, super bowls won, career passing yds, and career passing TDs
    public Quarterback(String name, int numberOfSuperBowlsWon, 
                       int careerPassingYards, int careerPassingTouchdowns) {
        setName(name); 
        setNumberOfSuperBowlsWon(numberOfSuperBowlsWon);
        setCareerPassingYards(careerPassingYards);
        setCareerPassingTouchdowns(careerPassingTouchdowns);
    }

}


package main;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import quarterback.Quarterback;

public class Main {
    public static void main(String[] args) {
        // Declare and instantiate an ArrayList of Quarterback objects
        // "parameterized" ArrayList
        ArrayList<Quarterback> qbs = new ArrayList<Quarterback>();
        // Add Tom Brady to the qbs ArrayList
        qbs.add(new Quarterback("Tom Brady", 5, 66150, 488));
        // Add Andy Dalton to the qbs ArrayList
        qbs.add(new Quarterback("Andy Dalton", 0, 25534, 167));
        // Add David Klingler
        qbs.add(new Quarterback("David Klingler", 0, 3994, 16));
        // Add Brett Favre
        qbs.add(new Quarterback("Brett Favre", 1, 71838, 508));
        // Add Boomer Esiason
        qbs.add(new Quarterback("Boomer Esiason", 0, 37920, 247));

        Quarterback JT = new Quarterback("JT Barrett IV", 0, 0, 0);
        qbs.add(JT);

        Collections.sort((List<Quarterback>) qbs);
    }
}

0 个答案:

没有答案