Skip to content

Commit

Permalink
feat: Social Media Screen Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Apr 23, 2024
1 parent 9a62d72 commit d20871c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 69 deletions.
Binary file modified challenge-backend/challenge01-conversormoedas/bin/App.class
Binary file not shown.
Binary file not shown.
107 changes: 53 additions & 54 deletions challenge-backend/challenge01-conversormoedas/src/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,43 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;


public class App {
public static void main(String[] args) throws Exception , InterruptedException{
public static void main(String[] args) throws Exception, InterruptedException {

@SuppressWarnings("resource")
Scanner scanner = new Scanner(System.in);
RenderScreen renderscreen = new RenderScreen();
char novaConversao = 'S';
String json = "";
int[] actualCurrency = {0,146,42,20,42,20,146};
int[] actualCurrency = { 0, 146, 42, 20, 42, 20, 146 };

while (novaConversao == 'S') {
novaConversao = 'N';
renderscreen.generateMenu();
int opcaoSelecionada = scanner.nextInt();

if (opcaoSelecionada > 0 && opcaoSelecionada < 7) {
System.out.println("DIGITE O VALOR A CONVERTER");
double value = scanner.nextDouble();

// Buscar Cotação
try{
HttpClient client = HttpClient.newHttpClient();

HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://v6.exchangerate-api.com/v6/24be77b499ee270705b19218/latest/"+currentCurrency(opcaoSelecionada)))
.build();

HttpResponse<String> response = client
.send(request,HttpResponse.BodyHandlers.ofString());

json = response.body();
// Buscar Cotação
try {
HttpClient client = HttpClient.newHttpClient();

HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://v6.exchangerate-api.com/v6/24be77b499ee270705b19218/latest/"
+ currentCurrency(opcaoSelecionada)))
.build();

HttpResponse<String> response = client
.send(request, HttpResponse.BodyHandlers.ofString());

json = response.body();
} catch (Exception e) {
System.out.println("Cotação indisponível :"+ e.getMessage());
System.out.println("Cotação indisponível :" + e.getMessage());
}

double currency = convertCurrency(0,value,extractJson(json,actualCurrency[opcaoSelecionada]));
double currency = convertCurrency(0, value, extractJson(json, actualCurrency[opcaoSelecionada]));
renderscreen.selectConversion(opcaoSelecionada);
renderscreen.printConversion(value, currency);

Expand All @@ -55,46 +55,46 @@ public static void main(String[] args) throws Exception , InterruptedException{
}

System.out.println("************************");
System.out.println("OBRIGADO POR UTILIZAR O ");
System.out.println("OBRIGADO POR UTILIZAR O ");
System.out.println("CONVERSOR DE MOEDAS. ");
System.out.println(" ");
System.out.println("PROGRAMA ONE 2024 ");
System.out.println("PROGRAMA ONE 2024 ");
System.out.println("*******************************************");
System.out.println("------------------------");
System.out.println(" PROGRAMA ONE 2024 ");
System.out.println(" Aluno: Douglas Ramos ");
System.out.println("linkedin.com/in/douglas-ramos-dev");
System.out.println("youtube.com/@profdomdev");
System.out.println("github.com/douginfodev");
System.out.println("************************");
}

public static double convertCurrency(int operation, double value1, double value2){
public static double convertCurrency(int operation, double value1, double value2) {
double valueConverted = 0;

if(operation == 0){
valueConverted = (value1 * value2);

if (operation == 0) {
valueConverted = (value1 * value2);
} else {
valueConverted = (value1 / value2);
}
else
{
valueConverted = (value1 / value2);
}


System.out.println("Value 2 ="+value2);
System.out.println("Value 2 =" + value2);
return valueConverted;
}

public static double extractJson(String json,int posicao) throws Exception {
public static double extractJson(String json, int posicao) throws Exception {
double value = 0.0;
try{
String[] listaValores = json.split("rates");
String[] currency = listaValores[1].split(",");
int auxStrLength = currency[posicao].length();
String auxStr = currency[posicao].substring(9,auxStrLength);
value = Double.parseDouble(auxStr);
try {
String[] listaValores = json.split("rates");
String[] currency = listaValores[1].split(",");
int auxStrLength = currency[posicao].length();
String auxStr = currency[posicao].substring(9, auxStrLength);
value = Double.parseDouble(auxStr);
return value;
} catch (Exception e) {
System.out.println("Erro na Cotação" + e.getMessage());
}
return value;
} catch (Exception e) {
System.out.println("Erro na Cotação"+ e.getMessage());
}
return value;
}

public static String currentCurrency(int option){
public static String currentCurrency(int option) {
String currency = "";

switch (option) {
Expand All @@ -104,17 +104,16 @@ public static String currentCurrency(int option){
break;
case 3:
case 4:
currency = "USD";
currency = "USD";
break;
case 5:
case 6:
currency = "EUR";
case 5:
case 6:
currency = "EUR";
break;
default:
default:
break;
}

return currency;
}
}

}
30 changes: 15 additions & 15 deletions challenge-backend/challenge01-conversormoedas/src/RenderScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,38 +39,38 @@ public void selectConversion(int option) {
this.currencyConverted = "DOLAR (US$)";
break;
case 2:
this.currency = "REAL (R$)";
this.currency = "REAL (R$)";
this.currencyConverted = "EURO (€$)";
break;
case 3:
this.currency = "DOLAR (US$)";
this.currency = "DOLAR (US$)";
this.currencyConverted = "REAL (R$)";
break;
break;
case 4:
this.currency = "DOLAR (US$)";
this.currencyConverted = "EURO (€$)";
break;
case 5:
this.currency = "EURO (€$)";
this.currency = "EURO (€$)";
this.currencyConverted = "REAL (R$)";
break;
case 6:
this.currency = "EURO (€$)";
this.currency = "EURO (€$)";
this.currencyConverted = "DOLAR (US$)";
break;
break;
}
}

public void printConversion(double value1, double value2) {
System.out.println("===========================");
System.out.println(" VALOR = "+value1);
System.out.println("---------------------------");
System.out.println(" VALOR CONVERTIDO ");
System.out.print(this.currency+" = ");
System.out.printf("%.2f %n",value1);
System.out.println("========================");
System.out.println(" VALOR = " + value1);
System.out.println("------------------------");
System.out.println(" VALOR CONVERTIDO ");
System.out.print(this.currency + " = ");
System.out.printf("%.2f %n", value1);
System.out.println(" || ");
System.out.print(this.currencyConverted+" = ");
System.out.printf("%.2f %n",value2);
System.out.println("===========================");
System.out.print(this.currencyConverted + " = ");
System.out.printf("%.2f %n", value2);
System.out.println("========================");
}
}

0 comments on commit d20871c

Please sign in to comment.