T
TomJoe
Gast
Java:
import java.util.Scanner;
import java.net.*;
import java.io.*;
public class Währungsrechner {
public static String readRSSFeed(String urlAddress) {
try{
URL rssUrl = new URL(urlAddress);
BufferedReader in = new BufferedReader(new InputStreamReader(rssUrl.openStream()));
String sourceCode = "";
String line;
while ((line = in.readLine()) != null) {
int titleEndIndex = 0;
int titleStartIndex = 0;
while (titleStartIndex >= 0) {
titleStartIndex = line.indexOf("<description>", titleEndIndex);
if (titleStartIndex >= 0) {
titleEndIndex = line.indexOf("</description>", titleStartIndex);
sourceCode += line.substring(titleStartIndex + "<description>".length(), titleEndIndex) + "\n";
if(!(sourceCode.contains("US-Dollar"))) {
sourceCode = "";
}
}
}
}
String[] split = sourceCode.split("1[^0-9]*= ");
String USD1 = split[1];
String[] split1 = USD1.split("US-Dollar");
double a = Double.parseDouble(split1[0]);
extracted(a);
in.close();
sourceCode = "";
return sourceCode;
} catch (MalformedURLException ue){
System.out.println("Malformed URL");
} catch (IOException ioe){
System.out.println("Something went wrong reading the contents");
}
return null;
}
private static void extracted(double a) {
System.out.println(a);
}
public static void main(String[] args) {
System.out.println("Willkommen zum aktuellen Wechselkurs und Währungsrechner \nHave Fun \n");
System.out.println("Der aktuelle umrechnungs Wert liegt bei ");
System.out.println( readRSSFeed("https://de.fx-exchange.com/eur/rss.xml"));
Integer EingabeJA;
System.out.println("Wenn du mit der aktuellen Zahl weiterrechnen willst, musst du als erstes 0 in die Eingabe eintippen und die Zahl aktualisieren. Dann musst du das Programm nochmal \nlaufen lassen und dieses mal 1 eingeben. Nun muss die Zahl womit gerechnet werden soll eingetippt werden. :)");
@SuppressWarnings("resource")
Scanner Eingabe = new Scanner(System.in);
EingabeJA = Eingabe.nextInt();
if (EingabeJA == 1){
double USD;
@SuppressWarnings("resource")
Scanner EingabeV2 = new Scanner(System.in);
double Euroeingabe = EingabeV2.nextDouble();
USD = Euroeingabe * 1.2195;
System.out.println(Euroeingabe + "€ sind " + USD + " US-Dollar");
}
else if (EingabeJA == 0)
{
}
else
{
System.out.println("Error! Make sure you typed everything correct, and try then try again");
}
}
}
Ich will die Variabel so benutzen USD = Euroeingabe*a
Doch ich kann sie nicht einfach einsetzten. Hat einer eine Idee.
Vielen Dank schon im Voraus