Composite Classes

Run Settings
LanguageJava
Language Version
Run Command
//WeatherMachine.java public class WeatherMachine { Thermometer thermometer; public WeatherMachine() { thermometer = new Thermometer(); } private double[] getPastTemperature() { double[] result = new double[24]; for(int i = 0; i < result.length; i++) { result[i] = thermometer.getTemperature(); } return results; } public void getWeatherReport() { System.out.println("Your last 24 hours:"); double[] temps = getPastTemperatures(); for(int i = 0; i < temp.length; i++) { System.out.println(i + " :00 " + temps[i] + " degrees "); } } } // Thermometer.java public class Thermometer { public double getTemperature() { return Math.round(Math.random() * 112 + 1); } } //Simulation.java public class Simulation { public static void main(String[] args) { WeatherMachine wm = new WeatherMachine(); wm.getWeatherReport(); } }
//WeatherMachine.java public class WeatherMachine { Thermometer thermometer; String city; public WeatherMachine() { this("Reston"); thermometer = new Thermometer(); } public WeatherMachine(String city) { this.city = city; } private double[] getPastTemperature() { double[] result = new double[24]; for(int i = 0; i < result.length; i++) { result[i] = thermometer.getTemperature(); } return result } public void getWeatherReport() { System.out.println("Your Current location: " + city); System.out.println("Your last 24 hours: "); double[] temps = getPastTemperature(); for(int i = 0; i < temp.length; i++) { System.out.println(i + ":00" + temps[i] + " degrees"); } } } //Thermometer.java public class Thermometer { public double getTemperature() { return Math.round(Math.random() * 112 + 1); } } //Simulation.Java public class Simulation { public stativ void main(String[] args) { WeatherMachine wm = new WeatherMachine(); wm.getWeatherReport(); } }
Editor Settings
Theme
Key bindings
Full width
Lines