import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Scanner;
public class BuscaCoin {
Scanner input = new Scanner(System.in);
public void buscaCripto() throws IOException, InterruptedException {
System.out.println("Digite o nome da criptmoeda: ");
String moeda = input.nextLine();
var busca = "https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=" + moeda + "&x_cg_demo_api_key=" + "CG-yxE3Jz7JQ88Rb7g9q47JV1Xu";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(busca))
.build();
HttpResponse<String> response = client
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Essas são as informações sobre a criptomoeda pesquisada.\n");
System.out.println(response.body());
}
}
//Principal
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException, InterruptedException {
System.out.println("*********COTAÇÃO DE CRIPTOMOEDAS**********\n");
BuscaCoin novaBusca = new BuscaCoin();
novaBusca.buscaCripto();
}
}