Advertisement
Guest User

Untitled

a guest
Sep 4th, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. public class valuteConverter {
  2. String dollars;
  3. Document doc;
  4. double dollarRubleCuourse = Double.parseDouble(usd());
  5. public String usd(){
  6. try{
  7. doc = Jsoup.connect("http://www.cbr.ru/").get();
  8. Element dollar = doc.select(".weak").first();
  9. dollars = dollar.text();
  10. }catch(IOException e){
  11. e.printStackTrace();
  12. }
  13. dollars = dollars.substring(5, dollars.length()).replace(',', '.');
  14. return dollars;
  15. }
  16.  
  17. public static void main(String[] args) {
  18. String s= JOptionPane.showInputDialog("Что конвертировать? Доллары/рубли?");
  19. if(s.toLowerCase().equals("доллары")){
  20. String z = JOptionPane.showInputDialog("Введите сумму");
  21. double a = Integer.parseInt(z)*new valuteConverter().dollarRubleCuourse;
  22. JOptionPane.showMessageDialog(null, a + " " + "рублей");
  23. }else if(s.toLowerCase().equals("рубли")){
  24. String z = JOptionPane.showInputDialog("Введите сумму");
  25. double a = Integer.parseInt(z)/new valuteConverter().dollarRubleCuourse;
  26. JOptionPane.showMessageDialog(null, a + " " + "рублей");
  27. }else{
  28. JOptionPane.showMessageDialog(null, "Выбранная валюта мне неизвестна:(");
  29. }
  30. }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement