吸气剂工作不正常

时间:2018-08-19 21:55:56

标签: java input output report getter-setter

我正在处理一个报告文件,以调用多种方法对外部报告文件起作用。下面是我的report.java文件,getter元素似乎不起作用。这些元素是generateReport和isServerActive。这就是我试图找出的所有其他方法都可以正常工作的原因,但是这两种方法似乎仍然挂断了。

class Report {
//Variables to be used within my methods/functions below
private static String serverName;
private static String userName;
private static String password;
private String reportName;
private int numParameters;
private int reportParameter;
private String reportParameterString;
private static String outputType;
private static String systemName;
private static String genReport;
private static boolean active;

// Constructor
Report(String name){
    reportName = name; 

}

//setServerName method, assigned variable serverName the value passed into "name"
public static void setServerName(String name){
    serverName = name;
}

//setUserName method, assigned variable userName the value passed into "user"
public static void setUserName(String user){
    userName = user;

}

//setPassword method, assigned variable password the value passed into "pw"
public static void setPassword(String pw){
    password = pw;
}

   //setNumParameters method, assigned variable numParameters the value 
     passed into int "numParm" 
   public void setNumParameters (int numParm){
   numParameters = numParm;
   }

   //setParameter method, assigned variable reportParameter the value 
passed into int "reportParam" 
   //Assigned variable reportParameterString the value passed into 
"param"
   public void setParameter (int reportParam, String param){
       reportParameter = reportParam;
       reportParameterString = param;

   }

   //setOutputType method, assigned variable outputType the value passed 
into "output" 
   public void setOutputType (String output){
       outputType = output;

   }

   //setReportSystemName method, assigned variable systemName the value 
passed into "reportSystemName"
   public void setReportSystemName (String reportSystemName){
       systemName = reportSystemName;
   }

   public void generateReport(String reportGen){
       genReport = reportGen;

   }

   public void isServerActive(boolean isActive){
       active = isActive;

   }


}

这是我要调用上述所有方法的文件

public class ReportClassPrinter {
public static void main(String[] args) {


    //Set the server name
    Report.setServerName("\\\\fancyServer");
    Report.setUserName("NHAUser");
    Report.setPassword("NHAPassword");

    //Create the two reports
    Report report1 = new Report("Report #1");
    Report report2 = new Report("Report #2");

    //Set the numbe of parameters for each report
    report1.setNumParameters(2);
    report2.setNumParameters(4);

    //Add the needed parameters, Report should make sure I am not trying to break it
    report1.setParameter(0, "01/01/1970");
    report1.setParameter(1, "01/01/2018");
    report1.setParameter(2, "pjdt");

    report2.setParameter(0, "08/01/2017");
    report2.setParameter(1, "08/01/2018");
    report2.setParameter(2, "notpjdt");
    report2.setParameter(3, "THIS IS A PARAMETER");
    report2.setParameter(4, "THIS WON'T BE ADDED");

    //Set the output type
    report1.setOutputType("pdf");
    report2.setOutputType("xls");

    //Set the report system name:
    report1.setReportSystemName("reportNumberOne.rdl");
    report2.setReportSystemName("reportNumberTwo.rdl");


    //Display the Report information
    System.out.println(report1.generateReport());
    System.out.println("Server up is: " + Report.isServerActive());
    System.out.println(report2.generateReport());
    System.out.println("Server up is: " + Report.isServerActive());


    //Change the server - notice how chaning this once, affects ALL reports
    System.out.println("\nUpdating Server information\n");
    Report.setServerName("\\\\SercureServerName");
    Report.setUserName("SecureNHAUser");

    //Again display the Report information
    System.out.println(report1.generateReport());
    System.out.println("Server up is: " + Report.isServerActive());
    System.out.println(report2.generateReport());
    System.out.println("Server up is: " + Report.isServerActive());


}

}

1 个答案:

答案 0 :(得分:1)

您需要

  1. 获取者最后一行的return声明
  2. 更改函数的返回类型
  3. 从函数签名中删除参数,因为您不使用参数调用函数
  4. 将static添加到返回类型

可以按预期在Main函数上工作。在getter中所做的只是为变量分配了值。

class Report {
   [...] 
   public static String generateReport(){
       return genReport;
   }

   public static boolean isServerActive(){
       return active;
   }
}