package DNA.java;
import java.awt.*;
import java.text.*;
import java.io.* ;
import java.util.*;
import java.lang.*;
import javax.swing.*;
import java.net.* ;
public class Berechnung {
// private HTMLEditorKit htmlKit;
// private HTMLDocument doc;
public Berechnung() {}
public static void main(String[] berechnung) throws Exception {
BufferedReader br0 = new BufferedReader(new InputStreamReader(System.in));
String[] o ={"nick","read","datum1","onMin"};
URL url;
int time = 0;
double onMinD;
int i =0;
String[] nicks = {"","","","","","","","","",""};
Double[] werte = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
String sy = "";
String gut ="";
String nick = "";
String read = "";
String datum1 = "";
String onMin ="";
int y = 0;
System.out.println("bitte zehn nicks eingeben,diese bitte mit komma trennen");
//beispieleingabe die funktioniert :
// Bussiiigirl,Freier Noi,Mirko24,Gina D,Audi 80 B4 Fahrer,Essener84,vbmaus,XXBadBoyT,boah ey 110,Soul1982
DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
DateFormat defaultDate = DateFormat.getDateInstance();
String datum = defaultDate.format(new java.util.Date());
Date to = df.parse(datum);
StringTokenizer st = new StringTokenizer(br0.readLine() , ",");
while (st.hasMoreTokens()) {
for (int x =0; x <= 9; x++) {
nick = "http://knuddels.de/ww/"+st.nextToken();
if (nick.contains(" "));
{
nick = nick.replace(" ","_");
url = new URL(nick);
Exception fehler = new Exception();
}
//System.out.println(nick);
BufferedReader br1 = new BufferedReader(new InputStreamReader(url.openStream()));
while((read = br1.readLine()) != null){
read = read.replace("<HTML><HEAD><META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=", "");
read = read.replace("\"></HEAD></HTML>", "");
url = new URL(read);
BufferedReader br2 = new BufferedReader(new InputStreamReader(url.openStream()));
while((read = br2.readLine()) != null){
nick = nick.replace("http://knuddels.de/ww/", "");
if (read.contains("<FONT FACE=\"Arial\">
[B]"))//(b == 45)
{
read = read.replace("<FONT FACE=\"Arial\">
[B]", "");
read = read.replace("<FONT COLOR=\"#000000\" SIZE=2>[/B]<FONT COLOR=\"000000\"> hat sich am [B]", "");
if (read.contains("http://spenden.knuddels.de")) {
read = read.replace("<a href=\"http://spenden.knuddels.de\" target=_blank><img border=0 src=\"../../images/ico_ribbon.gif\"></a> ", "") ;
read = read.replace("<FONT COLOR=\"#000000\" SIZE=2>[/B]<FONT COLOR=\"000000\">hat sich am [B]", "");
}
if (read.contains("&")) {
read = read.replace("&", " ");
}
if (nick.contains("_")) {
nick = nick.replace("_", " ");
}
// System.out.println(nick);
int zeichen = nick.length();
int k= 0;
int h = nick.length();
if (zeichen == nick.length()){
nick = read.substring(0, h);
k = nick.length() + 10 ;
datum1 = read.substring( h, k);
// System.out.println("das ist datum1 " + datum1);
String time1 = read.substring(h + 39, h + 47);
String blah = nick + datum1 + "[/B]<FONT COLOR=\"000000\"> um " + time1 + " bei Knuddels registriert und seitdem schon [B]";
read = read.replace(nick + datum1 + "[/B]<FONT COLOR=\"000000\"> um " + time1 + " bei Knuddels registriert und seitdem schon [B]", "");
// System.out.println(read);
String ez = read.substring(0, 10);
String[] n = {"0","1","2","3","4","5","6","7","8","9"};
for (int a =0; a <= 9; a++) {
String t = ez.substring(a, a+1);
for (int j =0; j <= 9; j++) {
if (t.contains(n[j])){
onMin = onMin + n[j];
// System.out.println(onMin);
}}}
// System.out.println("Minuten = " + onMin);
// System.out.println("Datum = " + datum1);//df.format()
onMinD = Double.parseDouble( onMin ) ;
// System.out.println(onMinD);
Date from = df.parse(datum1);
double diffMillis = to.getTime() - from.getTime();
double diffMins = diffMillis / (1000 * 60 );
//ausrechnen der minuten und der stunden
double erg = (100 / diffMins ) * (double) onMinD ;
double stunden = erg * 0.24 ;
double minuten = stunden * 60 ;
//Runden der Werte auf zwei stellen hinter dem komma
erg = Math.round( erg * 100. ) / 100.;
// System.out.println(erg);
stunden = Math.round( stunden * 100. ) / 100.;
minuten = Math.round( minuten * 100. ) / 100.;
String som = "";
String hours = "Das entspricht " + stunden + " Stunden am Tag";
String hour = "Genau eine Stunde am Tag";
String mins = "das sind " + minuten + " minuten am tag";
//wenn es weniger als eine stunde ist dann werden die minuten ausgegeben!
if ( stunden > 1 ) {
som = hours;
} else {
if (stunden == 1){
som = hour;
}
if ( stunden < 1) {
som = mins;
}
}
String diff = "Die Differenz in Minuten ist " + diffMins + " Minuten" ;
String regDateO = "Du hast dich am " + df.format(from) + " hier registriert";
String onTime = "Du warst " + erg + " % Deines Lebens hier Online seit Du dich registriert hast";
String sOderM = som;
//Eigendliche Ausgabe.
// System.out.println(diff);
// System.out.println(regDateO);
// System.out.println(onTime);
// System.out.println(som);
// System.out.println("#" + regDateO + "#" + onTime + "#" + som);
onMin = "" + "";
nicks[i] = nick ;
werte[i] = erg ;
i++;
//aufräumen
} //2. if bedingung wird geschlossen
} //1. if bedingung wird geschlossen
} //2. while schleife wird geschlossen
br2.close();
} //1. while schleife wird geschlossen
br1.close();
}
br0.close();
}
final Map<String, Double> map = new HashMap<String, Double>();
map.put(nicks[0],werte[0]);
map.put(nicks[1],werte[1]);
map.put(nicks[2],werte[2]);
map.put(nicks[3],werte[3]);
map.put(nicks[4],werte[4]);
map.put(nicks[5],werte[5]);
map.put(nicks[6],werte[6]);
map.put(nicks[7],werte[7]);
map.put(nicks[8],werte[8]);
map.put(nicks[9],werte[9]);
Comparator<String> comparator = new Comparator<String>() {
public int compare(String a, String b) {
return -map.get(a).compareTo(map.get(b));
}
};
Map<String, Double> sortedMap = new TreeMap<String, Double>(comparator);
sortedMap.putAll(map);
for (String s : sortedMap.keySet()) {
for (int e = s.length(); 26 > e; e++)
{
s ="-" + s;
}
System.out.println("#" + s + " -> " + sortedMap.get(s));
}
} //main methode wird geschlossen
} //programm wird geschlossen