Advertisement
Guest User

Untitled

a guest
May 27th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.26 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Task2{
  4. static Scanner scanner = new Scanner(System.in);
  5. static double eur, dol, rub;
  6. static boolean ProgramState = true;
  7. static final int DOLLAR = 1;
  8. static final int EURO = 2;
  9. static final int RUBLE = 3;
  10. static final int GRIVNA = 4;
  11. static int initialCurrency, toCurrency;
  12.  
  13. public static void main(String args[]){
  14. coefOnStartUp();
  15. int yesNo;
  16. do{
  17. select();
  18. calc(initialCurrency, toCurrency);+-
  19.  
  20. do{
  21. exitPrinter();
  22. yesNo = scanner.nextInt();
  23. if(yesNo == 1){
  24. ProgramState = true;
  25. }else if(yesNo == 2){
  26. ProgramState = false;
  27. System.out.println("THX");
  28. }else{
  29. System.out.println("Try choose again:");
  30. exitPrinter();
  31. }
  32. }while(yesNo < 1 && yesNo > 2);
  33. }while(ProgramState);
  34.  
  35. }
  36.  
  37. public static void select(){
  38. System.out.println("Which currency u want to exchange?");
  39. System.out.println("1. Dollar");
  40. System.out.println("2. Euro");
  41. System.out.println("3. Rub");
  42. System.out.println("4. GRN");
  43. initialCurrency = scanner.nextInt();
  44. System.out.println("To which currency?");
  45. System.out.println("1. Dollar");
  46. System.out.println("2. Euro");
  47. System.out.println("3. Rub");
  48. System.out.println("4. GRN");
  49. toCurrency = scanner.nextInt();
  50.  
  51. }
  52.  
  53. public static void coefOnStartUp(){
  54. System.out.println("Insert coefs for money exchange");
  55.  
  56. System.out.println("EURO:");
  57. eur = scanner.nextDouble();
  58. System.out.println("DOLLAR");
  59. dol = scanner.nextDouble();
  60. System.out.println("RUB");
  61. rub = scanner.nextDouble();
  62.  
  63. }
  64.  
  65. public static void exitPrinter(){
  66. System.out.println("Do u want exchange again: ");
  67. System.out.println("1. Yeap");
  68. System.out.println("2. No, thx!");
  69. }
  70.  
  71. public static void calc(int from, int to){
  72. double temp;
  73.  
  74. switch(from){
  75. case DOLLAR:
  76. fromDollar(to);
  77. break;
  78. case EURO:
  79. fromEuro(to);
  80. break;
  81. case RUBLE:
  82. fromRubble(to);
  83. break;
  84. case GRIVNA:
  85. fromGrivna(to);
  86. break;
  87. }
  88. }
  89.  
  90. public static void fromDollar(int to){
  91. double temp;
  92. if(to == DOLLAR){
  93. System.out.println("How many Dollars u want to exchange?: ");
  94. temp = scanner.nextDouble();
  95. System.out.println("U will Recieve " + temp + " Dollars");
  96. }
  97. if(to == EURO){
  98. System.out.println("How many Dollars u want to exchange?: ");
  99. temp = scanner.nextDouble();
  100. System.out.println("U will Recieve " + ((temp*dol)/eur) + " Euros");
  101. }
  102. if(to == RUBLE){
  103. System.out.println("How many Dollars u want to exchange?: ");
  104. temp = scanner.nextDouble();
  105. System.out.println("U will Recieve " + ((temp*dol)/rub) + " Rubbles");
  106. }
  107. if(to == GRIVNA){
  108. System.out.println("How many Dollars u want to exchange?: ");
  109. temp = scanner.nextDouble();
  110. System.out.println("U will Recieve " + temp*dol + " Grivnas");
  111. }
  112.  
  113. }
  114. public static void fromEuro(int to){
  115. double temp;
  116. if(to == DOLLAR){
  117. System.out.println("How many EUROS u want to exchange?: ");
  118. temp = scanner.nextDouble();
  119. System.out.println("U will Recieve " + ((temp*eur)/dol) + " Dollars");
  120. }
  121. if(to == EURO){
  122. System.out.println("How many EUROS u want to exchange?: ");
  123. temp = scanner.nextDouble();
  124. System.out.println("U will Recieve " + temp + " Euros");
  125. }
  126. if(to == RUBLE){
  127. System.out.println("How many EUROS u want to exchange?: ");
  128. temp = scanner.nextDouble();
  129. System.out.println("U will Recieve " + ((temp*eur)/rub) + " Rubbles");
  130. }
  131. if(to == GRIVNA){
  132. System.out.println("How many EUROS u want to exchange?: ");
  133. temp = scanner.nextDouble();
  134. System.out.println("U will Recieve " + temp*eur + " Grivnas");
  135. }
  136. }
  137. public static void fromGrivna(int to){
  138. double temp;
  139. if(to == DOLLAR){
  140. System.out.println("How many GRN u want to exchange?: ");
  141. temp = scanner.nextDouble();
  142. System.out.println("U will Recieve " + temp/dol + " Dollars");
  143. }
  144. if(to == EURO){
  145. System.out.println("How many GRN u want to exchange?: ");
  146. temp = scanner.nextDouble();
  147. System.out.println("U will Recieve " + temp/eur + " Euros");
  148. }
  149. if(to == RUBLE){
  150. System.out.println("How many GRN u want to exchange?: ");
  151. temp = scanner.nextDouble();
  152. System.out.println("U will Recieve " + temp/rub + " Rubbles");
  153. }
  154. if(to == GRIVNA){
  155. System.out.println("How many GRN u want to exchange?: ");
  156. temp = scanner.nextDouble();
  157. System.out.println("U will Recieve " + temp + " Grivnas");
  158. }
  159. }
  160. public static void fromRubble(int to){
  161. double temp;
  162. if(to == DOLLAR){
  163. System.out.println("How many RUB u want to exchange?: ");
  164. temp = scanner.nextDouble();
  165. System.out.println("U will Recieve " + ((temp*rub)/dol) + " Dollars");
  166. }
  167. if(to == EURO){
  168. System.out.println("How many RUB u want to exchange?: ");
  169. temp = scanner.nextDouble();
  170. System.out.println("U will Recieve " + ((temp*rub)/eur) + " Euros");
  171. }
  172. if(to == RUBLE){
  173. System.out.println("How many RUB u want to exchange?: ");
  174. temp = scanner.nextDouble();
  175. System.out.println("U will Recieve " + temp + " Rubbles");
  176. }
  177. if(to == GRIVNA){
  178. System.out.println("How many RUB u want to exchange?: ");
  179. temp = scanner.nextDouble();
  180. System.out.println("U will Recieve " + temp*rub + " Grivnas");
  181. }
  182. }
  183.  
  184.  
  185.  
  186.  
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement