Hi everybody
i am a beginner in java programming,
i want to read from url (which read a temperature from a website and then print it on screen, now subclass is:
into the main method :import java.net.*; import java.io.*; public class NetworkTemperatureSensor extends TemperaturSensor{ NetworkTemperatureSensor(String sid) { super(sid); } public Temperature read(){ Temperature t1 = new Temperature(); try { URL url = new URL("http://www.temperatur.nu/termo/boras/temp.txt"); URLConnection conn = url.openConnection(); InputStream uc = conn.getInputStream(); BufferedReader buffIn = new BufferedReader(new InputStreamReader(uc)); String s; while((s = buffIn.readLine())!= null) { System.out.println(s); } buffIn.close(); t1.setKelvin(Double.parseDouble(s)); } catch (Exception e) { System.out.println("Exception "+e); } return t1; } }
import java.util.*; import java.util.ArrayList; public class DataLoggerApplikation { public static void main(String[] args) { //private Temperature bb; DataLoggerApplikation app = new DataLoggerApplikation(); Temperature bb = new Temperature(); app.initiering(); for(int i = 0; i < 5; i++) { app.logSensorValues(); } app.skriva(); bb.equals(bb); } ArrayList<Sensor> sensorer; public void initiering() { sensorer = new ArrayList(); sensorer.add(new TemperaturSensor("ts")); sensorer.add(new FakeTemperatureSensor("fts")); sensorer.add(new FakeTemperatureSensor("fts2")); } public void logSensorValues() { Iterator itr = sensorer.iterator(); Sensor s; while(itr.hasNext()) { s = (Sensor) itr.next(); s.datalogger.add(s.read()); } } public void skriva() { Iterator itr = sensorer.iterator(); Sensor s; while(itr.hasNext()) { s = (Sensor)itr.next(); s.skrivaVarde(); } } }