Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.net.UnknownHostException;
- import java.util.HashMap;
- public class ClientMeteo {
- public static void main(String[] args){
- try {
- HashMap<String, String> nomVille = new HashMap<String, String>();
- nomVille.put("MTL", "Montréal");
- nomVille.put("TOR", "Toronto");
- nomVille.put("NY", "New York");
- String[] villes = new String[] {"MTL", "TOR", "NY"};
- double[] temperatures = new double[] {0.0, 0.0, 0.0};
- int[] humidites = new int[] {0, 0, 0};
- int[] vents = new int[] {0, 0, 0};
- for(int i = 0; i >= 0; i++){
- URL url = new URL(args[0]);
- InputStream is = url.openStream();
- BufferedReader reader = new BufferedReader(new InputStreamReader(is));
- PrintWriter writer = new PrintWriter(
- new BufferedWriter(
- new FileWriter("index.html")));
- writer.println("<!doctype html>");
- writer.println("<html>");
- writer.println("<head>");
- writer.println("<meta charset=\"utf-8\">");
- writer.println("<title>Meteo-Mediocre.ca/PrévisionDeLaSemaine</title>");
- writer.println("<meta http-equiv=\"refresh\" content=\"5\">");
- writer.println("<link rel=\"stylesheet\" href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css\" integrity=\"sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T\" crossorigin=\"anonymous\">\n");
- writer.println("<script src=\"ExtremeTemperature.js\"></script>");
- writer.println("</head>");
- writer.println("<body>");
- writer.println("<table class=\"table table-bordered\">");
- writer.println("<tr>");
- writer.println("<th>Ville</th>");
- writer.println("<th>Température</th>");
- writer.println("<th>Humidité</th>");
- writer.println("<th>Vents</th>");
- writer.println("</tr>");
- boolean pasFini = true;
- String ligne;
- while (pasFini){
- ligne = reader.readLine();
- if(ligne != null){
- int index = 0;
- if(ligne.split(",")[0].equals("MTL")){
- index = 0;
- } else if(ligne.split(",")[0].equals("TOR")){
- index = 1;
- } else {
- index = 2;
- }
- temperatures[index] = Double.parseDouble(ligne.split(",")[1]);
- humidites[index] = Integer.parseInt(ligne.split(",")[2]);
- vents[index] = Integer.parseInt(ligne.split(",")[3]);
- } else {
- pasFini = false;
- }
- }
- for(int b = 0; b != villes.length; b++){
- writer.println("<tr>");
- writer.println("<td>" + nomVille.get(villes[b]) + "</td>");
- if(temperatures[b] <= -30 || temperatures[b] >= 30){
- writer.println("<td bgcolor=\"red\">" + temperatures[b] + "</td>");
- } else {
- writer.println("<td>" + temperatures[b] + "</td>");
- }
- if(humidites[b] >= 90){
- writer.println("<td bgcolor=\"red\">" + humidites[b] + "</td>");
- } else {
- writer.println("<td>" + humidites[b] + "</td>");
- }
- if(vents[b] >= 100){
- writer.println("<td bgcolor=\"red\">" + vents[b] + "</td>");
- } else {
- writer.println("<td>" + vents[b] + "</td>");
- }
- writer.println("</tr>");
- }
- writer.println("</table>");
- writer.println("</body>");
- writer.println("</html>");
- writer.close();
- reader.close();
- Thread.sleep(5000);
- }
- } catch (MalformedURLException mue) {
- System.err.println("Erreur, l'URL est invalide");
- } catch (UnknownHostException uhe) {
- System.err.println("Erreur, le site est introuvable");
- } catch (FileNotFoundException fnfe) {
- System.err.println("Erreur, le fichier est introuvable!");
- } catch (IOException ioe) {
- ioe.printStackTrace();
- System.err.println("Erreur, Vous devez entrer une URL");
- } catch (InterruptedException ie){
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement