Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Task2{
- static Scanner scanner = new Scanner(System.in);
- static double eur, dol, rub;
- static boolean ProgramState = true;
- static final int DOLLAR = 1;
- static final int EURO = 2;
- static final int RUBLE = 3;
- static final int GRIVNA = 4;
- static int initialCurrency, toCurrency;
- public static void main(String args[]){
- coefOnStartUp();
- int yesNo;
- do{
- select();
- calc(initialCurrency, toCurrency);+-
- do{
- exitPrinter();
- yesNo = scanner.nextInt();
- if(yesNo == 1){
- ProgramState = true;
- }else if(yesNo == 2){
- ProgramState = false;
- System.out.println("THX");
- }else{
- System.out.println("Try choose again:");
- exitPrinter();
- }
- }while(yesNo < 1 && yesNo > 2);
- }while(ProgramState);
- }
- public static void select(){
- System.out.println("Which currency u want to exchange?");
- System.out.println("1. Dollar");
- System.out.println("2. Euro");
- System.out.println("3. Rub");
- System.out.println("4. GRN");
- initialCurrency = scanner.nextInt();
- System.out.println("To which currency?");
- System.out.println("1. Dollar");
- System.out.println("2. Euro");
- System.out.println("3. Rub");
- System.out.println("4. GRN");
- toCurrency = scanner.nextInt();
- }
- public static void coefOnStartUp(){
- System.out.println("Insert coefs for money exchange");
- System.out.println("EURO:");
- eur = scanner.nextDouble();
- System.out.println("DOLLAR");
- dol = scanner.nextDouble();
- System.out.println("RUB");
- rub = scanner.nextDouble();
- }
- public static void exitPrinter(){
- System.out.println("Do u want exchange again: ");
- System.out.println("1. Yeap");
- System.out.println("2. No, thx!");
- }
- public static void calc(int from, int to){
- double temp;
- switch(from){
- case DOLLAR:
- fromDollar(to);
- break;
- case EURO:
- fromEuro(to);
- break;
- case RUBLE:
- fromRubble(to);
- break;
- case GRIVNA:
- fromGrivna(to);
- break;
- }
- }
- public static void fromDollar(int to){
- double temp;
- if(to == DOLLAR){
- System.out.println("How many Dollars u want to exchange?: ");
- temp = scanner.nextDouble();
- System.out.println("U will Recieve " + temp + " Dollars");
- }
- if(to == EURO){
- System.out.println("How many Dollars u want to exchange?: ");
- temp = scanner.nextDouble();
- System.out.println("U will Recieve " + ((temp*dol)/eur) + " Euros");
- }
- if(to == RUBLE){
- System.out.println("How many Dollars u want to exchange?: ");
- temp = scanner.nextDouble();
- System.out.println("U will Recieve " + ((temp*dol)/rub) + " Rubbles");
- }
- if(to == GRIVNA){
- System.out.println("How many Dollars u want to exchange?: ");
- temp = scanner.nextDouble();
- System.out.println("U will Recieve " + temp*dol + " Grivnas");
- }
- }
- public static void fromEuro(int to){
- double temp;
- if(to == DOLLAR){
- System.out.println("How many EUROS u want to exchange?: ");
- temp = scanner.nextDouble();
- System.out.println("U will Recieve " + ((temp*eur)/dol) + " Dollars");
- }
- if(to == EURO){
- System.out.println("How many EUROS u want to exchange?: ");
- temp = scanner.nextDouble();
- System.out.println("U will Recieve " + temp + " Euros");
- }
- if(to == RUBLE){
- System.out.println("How many EUROS u want to exchange?: ");
- temp = scanner.nextDouble();
- System.out.println("U will Recieve " + ((temp*eur)/rub) + " Rubbles");
- }
- if(to == GRIVNA){
- System.out.println("How many EUROS u want to exchange?: ");
- temp = scanner.nextDouble();
- System.out.println("U will Recieve " + temp*eur + " Grivnas");
- }
- }
- public static void fromGrivna(int to){
- double temp;
- if(to == DOLLAR){
- System.out.println("How many GRN u want to exchange?: ");
- temp = scanner.nextDouble();
- System.out.println("U will Recieve " + temp/dol + " Dollars");
- }
- if(to == EURO){
- System.out.println("How many GRN u want to exchange?: ");
- temp = scanner.nextDouble();
- System.out.println("U will Recieve " + temp/eur + " Euros");
- }
- if(to == RUBLE){
- System.out.println("How many GRN u want to exchange?: ");
- temp = scanner.nextDouble();
- System.out.println("U will Recieve " + temp/rub + " Rubbles");
- }
- if(to == GRIVNA){
- System.out.println("How many GRN u want to exchange?: ");
- temp = scanner.nextDouble();
- System.out.println("U will Recieve " + temp + " Grivnas");
- }
- }
- public static void fromRubble(int to){
- double temp;
- if(to == DOLLAR){
- System.out.println("How many RUB u want to exchange?: ");
- temp = scanner.nextDouble();
- System.out.println("U will Recieve " + ((temp*rub)/dol) + " Dollars");
- }
- if(to == EURO){
- System.out.println("How many RUB u want to exchange?: ");
- temp = scanner.nextDouble();
- System.out.println("U will Recieve " + ((temp*rub)/eur) + " Euros");
- }
- if(to == RUBLE){
- System.out.println("How many RUB u want to exchange?: ");
- temp = scanner.nextDouble();
- System.out.println("U will Recieve " + temp + " Rubbles");
- }
- if(to == GRIVNA){
- System.out.println("How many RUB u want to exchange?: ");
- temp = scanner.nextDouble();
- System.out.println("U will Recieve " + temp*rub + " Grivnas");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement