Question: JAVA Create a test (driver) program called TestLab10.java with a main( ) method to test the methods you created in the SolarPanel class. You should
JAVA Create a test (driver) program called TestLab10.java with a main( ) method to test the methods you created in the SolarPanel class. You should have TestLab10.java stored in the same directory as SolarPanel.java, so it is not necessary to use an import statement. The main method in TestLab10.java should implement at least these steps:
Create SolarPanel panelOne using the default constructor. Then, set the openCircuitVoltage to 20.0, nominalVoltage to 12, and cellType to "Mono-crystalline" using the appropriate mutator methods.
Print panelOne with System.out.println. This should automatically call the toString method you have written. System.out.println(panelOne);
Change the openCircuitVoltage of panelOne to 150.0. (This is an invalid value.)
Print the openCircuitVoltage of panelOne.
Change the nominalVoltage of panelOne to -10. (This is an invalid value.)
Print the nominalVoltage of panelOne.
Create SolarPanel panelTwo using the constructor that accepts 3 parameters. Pass actual parameter values ( 40.0, 24, "Mono-crystalline").
Print (on separate lines) the openCircuitVoltage of panelTwo, the nominalVoltage of panelTwo, and the cellType of panelTwo. (This will test the accessor methods.)
Change the openCircuitVoltage of panelTwo to 0.
Print the openCircuitVoltage of panelTwo.
Change the cellType of panelTwo to "Vinyl Polymer".
Print the cellType of panelTwo.
Print panelTwo using System.out.println
SolarPanel.java code that needs to be tested:
public class SolarPanel{
private double openCircuitVoltage; private int nominalVoltage; private String cellType;
public SolarPanel() {
openCircuitVoltage = 40; nominalVoltage = 12; cellType = "Mono-crystalline";
}//SolarPanel()
public SolarPanel(double openCircuitVoltage, int nominalVoltage, String cellType) {
super(); this.openCircuitVoltage = openCircuitVoltage; this.nominalVoltage = nominalVoltage; this.cellType = cellType;
}//SolarPanel
public double getOpenCircuitVoltage() {
return openCircuitVoltage;
}//getOpenCircuitVoltage
public void setOpenCircuitVoltage(double openCircuitVoltage) {
if(openCircuitVoltage < 0 || openCircuitVoltage > 100) this.openCircuitVoltage = 40; else this.openCircuitVoltage = openCircuitVoltage;
}//setOpenCircuitVoltage
public int getNominalVoltage() {
return nominalVoltage;
}//getNominalVoltage
public void setNominalVoltage(int nominalVoltage) {
if(nominalVoltage < 12 || nominalVoltage > 24) this.nominalVoltage = 12; else this.nominalVoltage = nominalVoltage;
}//setNomincalVoltage
public String getCellType() {
return cellType;
}//getCellType
public void setCellType(String cellType) {
if(cellType.equalsIgnoreCase("Mono-crystalline") || cellType.equalsIgnoreCase("Poly-crystalline")) this.cellType = cellType; else this.cellType = "Mono-crystalline";
}//setCellType
public String toString() {
return "SolarPanel: Voc=" + openCircuitVoltage + " V Nom=" + nominalVoltage + " cellType=" + cellType;
}//toString()
}//SolarPanel
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
