spielekonsole spiel ausgeschrieben & TempRechner von Celsius zu Fahrenheit und Kelvin

This commit is contained in:
2025-02-26 08:56:57 +01:00
parent fbf9a10673
commit 1180e9887e
3 changed files with 24 additions and 17 deletions

View File

@@ -17,14 +17,14 @@ public class Spielekonsole {
public void spielnr() { public void spielnr() {
System.out.print("Bitte wähle ein Spiel von 1-3 aus: "); System.out.print("Bitte wähle ein Spiel von 1-3 aus: ");
int spielnr = scan.nextInt(); String spielnr = scan.next().toUpperCase();
if (spielnr == 1) { if (spielnr.equals("1") || spielnr.equals("EINS")) {
System.out.println("Du hast Spiel 1 ausgewählt!"); System.out.println("Du hast Spiel 1 ausgewählt!");
} }
else if (spielnr == 2) { else if (spielnr.equals("2") || spielnr.equals("ZWEI")) {
System.out.println("Du hast Spiel 2 ausgewählt!"); System.out.println("Du hast Spiel 2 ausgewählt!");
} }
else if (spielnr == 3) { else if (spielnr.equals("3") || spielnr.equals("DREI")) {
System.out.println("Du hast Spiel 3 ausgewählt!"); System.out.println("Du hast Spiel 3 ausgewählt!");
} }
else { else {

View File

@@ -2,6 +2,6 @@ package de.temprechner;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
TempRechner.fahrenheitEingabe(); TempRechner.rechner();
} }
} }

View File

@@ -5,21 +5,28 @@ import java.util.Scanner;
public class TempRechner { public class TempRechner {
//Scanner //Scanner
public static void fahrenheitEingabe() { public static void rechner() {
Scanner scan = new Scanner(System.in); Scanner scan = new Scanner(System.in);
System.out.print("Bitte gib die Temperatur in Fahrenheit ein: "); System.out.println("Was willst du umrechnen?");
double fahrenheit = scan.nextDouble(); System.out.println("1: Celsius zu Fahrenheit");
System.out.println("2: Celsius zu Kelvin");
System.out.print("Deine Wahl = ");
celsiusZuFahrenheit(fahrenheit); int auswahl = scan.nextInt();
}
//Fahrenheit zu Celsius System.out.print("Gib die Temperatur in Celsius ein: ");
public static double fahrenheitzuCelsius(double fahrenheit) { double celsius = scan.nextDouble();
return (fahrenheit - 32) * 1.8;
}
//Celsius zu Fahrenheit if (auswahl == 1) {
public static double celsiusZuFahrenheit(double celsius) { double fahrenheit = (celsius * 1.8) + 32;
return (celsius * 1.8) + 32; System.out.println(celsius + " °C entsprechen " + fahrenheit + " °F.");
} else if (auswahl == 2) {
double kelvin = celsius + 273.15;
System.out.println(celsius + " °C entsprechen " + kelvin + " K.");
} else {
System.out.println("Ungültige Auswahl! Bitte starte das Programm erneut.");
}
scan.close();
} }
} }