how to use a value of a variable from a loop in a void method?

You’re not passing any information into Weatherstation to calculate, so all the variables are zero.

Add a constructor like so:

public Weatherstation(double temperature, double windspeed, double windChillTemperature, double actualTemperature, double actualSpeed) {
    this.temperature = temperature;
    this.windspeed = windspeed;
    this.windChillTemperature = windChillTemperature;
    this.actualTemperature = actualTemperature;
    this.actualSpeed = actualSpeed;

Then modify your test class to pass in the variables:

public class WeatherstationTester {

     * @param args the command line arguments
    public static void main(String[] args) {

        for (int i = 0; i <= 10; i++) {
            Weatherstation w1 = new Weatherstation(i, i, i, i, i);


CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top