Informática, perguntado por Tricolor1013, 3 meses atrás

LISTA DE EXERCÍCIOS – FUNÇÕES
Escreva um programa que faça a conversão entre escalas de temperaturas. O programa deve possuir uma função
chamada menu que apresente as seguintes opções de conversão. 1. Celsius para Kelvin (Formula K=C+273); 2. Celsius
para Fahrenheit(Formula F=1,8C+32); 3. Kelvin para Fahrenheit (Formula F = 1.8 * (K - 273) + 32). Para cada conversão
deve ser implementada uma função. Exemplo de menu.
Sistema de Conversão de Temperaturas

MENU
1 Celsius para Kelvin
2 Celsius para Fahrenheit
3 Kelvin para Fahrenheit
0 Sair
OBS: Esse exercício tem que ser realizado em Java!! Replit ou NetBeans

Soluções para a tarefa

Respondido por fernandescro5
2

Resposta:

import java.util.Scanner;

public class Main

{

   

public static void main(String[] args) {

 

   Scanner temperatura = new Scanner(System.in);

   double temp, converter = 0;

   

   int menu = mostrarMenu();

   

   if (menu == 0){

       //System("clear");

       System.out.println("\nPROGRAMA FINALIZADO");

   }else if (menu == 1){

       System.out.println("\n-- OPÇÃO ESCOLHIDA: CELSIUS PARA KELVIN --");

       System.out.print("\nDigite a temperatura em Celsius: ");

       temp = temperatura.nextInt();

       converter = temp + 273;

       System.out.println(temp + "° Celsius é equivalente a " + converter + "° Kelvin");

   }else if (menu == 2){

       System.out.println("\n-- OPÇÃO ESCOLHIDA: CELSIUS PARA FAHRENHEIT --");

       System.out.print("\nDigite a temperatura em Celsius: ");

       temp = temperatura.nextInt();

       converter = 1.8 * temp + 32;

       System.out.println(temp + "° Celsius é equivalente a " + converter + "° Fahrenheit");

       

   }else if (menu == 3){

       System.out.println("\n-- OPÇÃO ESCOLHIDA: KELVIN PARA FAHRENHEIT --");

       System.out.print("\nDigite a temperatura em Kelvin : ");

       temp = temperatura.nextInt();

       converter = 1.8 * (temp - 273) + 32;

       System.out.println(temp + "° Kelvin  é equivalente a " + converter + "° Fahrenheit");

   }

}

   public static int mostrarMenu(){

       

       Scanner opcao = new Scanner(System.in);

       int valor = 0;

       

       System.out.println("----- MENU -----");

       System.out.println("1 Celsius para Kelvin");

       System.out.println("2 Celsius para Fahrenheit");

       System.out.println("3 Kelvin para Fahrenheit");

       System.out.println("0 Sair");

       

       System.out.print("Digite uma das opções acima: ");

       valor = opcao.nextInt();

       

       return valor;

   }

}


Tricolor1013: Vlw
Perguntas interessantes