我使用一个构造函数:无效的方法Decleration - 新的方法
Donor(String lastName, String firstName, String type, int age, double minutes)
而且我知道,我必须命名一样,它驻留在公共类,但是当我将我的花括号使它是由公共捐助者类包含我遇到了几个错误。
我的代码如下:
public class Program5
{
public static void main(String args[])
{
Arrays.sort(Donor, new lastNameComparator());
for (int i = 0; i < donor.length; i++)
{
System.out.println(Donor[i].getLastName());
}
Arrays.sort(Donor, new firstNameComparator());
for (int i = 0; i < donor.length; i++)
{
System.out.println(Donor[i].getFirstName());
}
Arrays.sort(Donor, new typeComparator());
for (int i = 0; i < donor.length; i++)
{
System.out.println(Donor[i].getType());
}
Arrays.sort(Donor, new ageComparator());
for (int i = 0; i < donor.length; i++)
{
System.out.println(Donor[i].getAge());
}
Arrays.sort(Donor, new minutesComparator());
for (int i = 0; i < donor.length; i++)
{
System.out.println(Donor[i].getMinutes());
}
}
public ArrayList<Donor> donorCSVList(String filePath) throws IOException
{
ArrayList<Donor> list = new ArrayList<Donor>();
Scanner scan = new Scanner(new File(filePath));
while (scan.hasNextLine())
{
String line = scan.nextLine();
String [] lineArray = line.split(",");
list.add(new Donor(lineArray[0], lineArray[1], lineArray[2], lineArray[3], lineArray[4]));
}
}
public class Donor
{
private String lastName;
private String firstName;
private String type;
private int age;
private double minutes;
}
public void Donor()
{
super();
type = "Not assigned";
age = 0;
minutes = 0.0;
}
Donor(String lastName, String firstName, String type, int age, double minutes)
{
super(lastName, firstName);
this.lastName = lastName;
this.firstName = firstName;
this.type = type;
this.age = age;
this.minutes = minutes;
}
public String getLastName()
{
return lastName;
}
public void setLastName(String lastName)
{
this.lastName = lastName;
}
public String getFirstName()
{
return firstName;
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public String getType()
{
return type;
}
public void setType(String type)
{
this.type = type;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
public double setMinutes()
{
return minutes;
}
public void getMinutes(double minutes)
{
this.minutes = minutes;
}
public class lastNameComparator implements Comparator
{
public String compare(Donor o1, Donor o2)
{
String lastName1 = o1.getLastName();
String lastName2 = o2.getLastName();
return lastName1.compareTo(lastName2);
}
}
public class firstNameComparator implements Comparator
{
public String compare(Donor o1, Donor o2)
{
String firsName1 = o1.getFirstName();
String firstName2 = o2.getFirstName();
return firstName1.compareTo(firstName2);
}
}
public class typeComparator implements Comparator
{
public string compare(Donor o1, Donor o2)
{
String type1 = o1.getType();
String type2 = o2.getType();
return type1.compareTo(type2);
}
}
public class ageComparator implements Comparator
{
public int compare(Donor o1, Date o2)
{
int age1 = o1.getAge();
int age2 = o2.getAge();
//return o2.getAge() - o1.getAge();
}
}
public class minutesComparator implements Comparator
{
public double compare(Donor o1, Donor o2)
{
double minutes1 = o1.getMinutes();
double minutes2 = o2.getMinutes();
//return o2.getMinutes() - o1.getMinutes();
}
}
}
而且我的错误是:
Program5.java:66: error: invalid method declaration; return type required
Donor(String lastName, String firstName, String type, int age, double minutes)
哪一行是错误?错误消息应该有行号。 –
我已经更新的问题更恰当地反映当前的问题,我现在面临的 – snitchyc
@snitchyc当发布StackOverflow上的示例代码,请您剥去所有不必要的行。 [创建一个简单的例子](http://stackoverflow.com/help/mcve),尽可能少的线仍然可以证明你的问题。作为一种副作用,这样做可以很好地回答你自己的问题。 –