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());
}
}
You need
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;
}
}