多个错误'('代码中的预期?

时间:2016-04-27 10:29:21

标签: java

import java.util.list;
import java.util.*;
public class PatientRecordSystem
{
  private int PATIENTMAX = 100;
  private int OBSERVATIONMAX = 50;

   private int current = 1;
   private int observationcurrent = 1;
   // current = patients, observationcurrent = observations count

   public PatientRecordSystem()
   {
       addPatient();
   }

   public void String addMeasurementObservationType()
   {

   }

   public void String addCategoryObservationType()
   {

   }

   public void String addPatient()
   {
   String PatientName = "James";
   String PatientID = "10122";

   }

   public void String addMeasurementObservation()
   {
   // for patient
   }

   public void String addCategoryObservation()
   {
   // for patient
   }
   // no interactive inputs, all static details.
   }
}

我不确定是什么导致错误显示为:

  

PatientRecordSystem.java:17:错误:'('预期           public void String addMeasurementObservationType()                              ^ PatientRecordSystem.java:22:错误:'('预期           public void String addCategoryObservationType()                              ^ PatientRecordSystem.java:27:错误:'('预期           public void String addPatient()                              ^ PatientRecordSystem.java:34:错误:'('预期           public void String addMeasurementObservation()                              ^ PatientRecordSystem.java:39:错误:'('预期           public void String addCategoryObservation()

3 个答案:

答案 0 :(得分:0)

  

第一个问题出在您的方法声明中,您无法声明方法public void String

如果您的方法不返回任何内容,则应声明:

public void addMeasurementObservationType(){
    // ...
}

如果你的方法返回一个String ,那么应该声明它:

public String addMeasurementObservationType(){
    return "the string to return";
}
  

第二个是您要导入java.util.list;

您应该导入:

import java.util.List;
  

第三个是你有一个额外的}

public void addCategoryObservation(){
    // for patient
    } <--- HERE
    // no interactive inputs, all static details.
}

我猜你的代码应该是这样的:

class PatientRecordSystem {
    private int PATIENTMAX = 100;
    private int OBSERVATIONMAX = 50;

    private int current = 1;
    private int observationcurrent = 1;


    public PatientRecordSystem(){
        addPatient();
    }

    public void addMeasurementObservationType(){

    }

    public void addCategoryObservationType(){

    }

    public void addPatient(){
        String PatientName = "James";
        String PatientID = "10122";
    }

    public void addMeasurementObservation(){
        // for patient
    }

    public void addCategoryObservation(){
        // for patient
        // no interactive inputs, all static details.
    }
}

答案 1 :(得分:0)

您不能拥有多种退货类型。如果将void声明为返回类型,则无法返回任何内容...我已修改您的代码以将类型返回为void。 (相应改变!)希望它有所帮助...

public class PatientRecordSystem {
private int PATIENTMAX = 100;
private int OBSERVATIONMAX = 50;

private int current = 1;
private int observationcurrent = 1;

// current = patients, observationcurrent = observations count

public PatientRecordSystem() {
    addPatient();
}

public void addMeasurementObservationType() {

}

public void addCategoryObservationType() {

}

public void addPatient() {
    String PatientName = "James";
    String PatientID = "10122";

}

public void addMeasurementObservation() {
    // for patient
}

public void addCategoryObservation() {
    // for patient
}
// no interactive inputs, all static details.
}

答案 2 :(得分:0)

你有类似的东西:

public void String addMeasurementObservationType()
   {

   }

这是一个矛盾/没有意义,你的方法应该返回String或者根本不返回任何内容(void

通过删除方法返回类型

中的String来修复它

实施例

public void addMeasurementObservationType()
   {

   }

这适用于所有具有相同错误的方法......