0

I am working on a report file to call multiple methods to function on an external Reporting file. Below is my report.java file and the getter elements do not seem to be working. These elements are generateReport and isServerActive. This is what I am trying to figure out as all of my other methods when called work properly, but these two still seem to be getting hung up.

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;

   }


}

Here is the file in which I am calling all of the above methods

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
    In Java, a method is defined by its name, the number of arguments, and the types of its arguments. Your Report class does not define a zero-argument generateReport method and it does not define a zero-argument isServerActive method. Therefore, your second source file should not even compile. – VGR Aug 19 '18 at 22:05
  • You are correct in that the second file does not compile. Would you suggest maybe using a constructor for the final two methods to develop the zero-argument? – cPlusPlusRocks Aug 19 '18 at 22:43
  • I just updated my isServerActive method, to reflect what I believe to be what you suggested @VGR any suggestions as to how to get this generateReport method? – cPlusPlusRocks Aug 20 '18 at 00:23

1 Answers1

1

You need

  1. return statement at the last line of your getters
  2. change return type of the function
  3. delete parameter from the function signature since you don't call the functions with argument
  4. add static to the return type

to work as you intended on Main function. What you did in your getters are just allocated value to the variable.

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

   public static boolean isServerActive(){
       return active;
   }
}
Soeun Park
  • 349
  • 3
  • 14
  • When using your return method my console is saying that the return is unnecessary and I still get compiler errors. – cPlusPlusRocks Aug 20 '18 at 00:58
  • I updated the answer a bit. As @VGR commented, you didn't call the function as you defined. That's why you got the compile error. – Soeun Park Aug 20 '18 at 01:07
  • I believe it is just in the isServerActive method. The error message is "non-static method isServerActive() cannot be referenced from a static context." – cPlusPlusRocks Aug 20 '18 at 01:08
  • So I needed to make the boolean method static and it worked out!! Thanks for the help. – cPlusPlusRocks Aug 20 '18 at 01:16