spielekonsole spiel ausgeschrieben & TempRechner von Celsius zu Fahrenheit und Kelvin
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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();
|
||||||
|
|
||||||
|
System.out.print("Gib die Temperatur in Celsius ein: ");
|
||||||
|
double celsius = scan.nextDouble();
|
||||||
|
|
||||||
|
if (auswahl == 1) {
|
||||||
|
double fahrenheit = (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.");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Fahrenheit zu Celsius
|
scan.close();
|
||||||
public static double fahrenheitzuCelsius(double fahrenheit) {
|
|
||||||
return (fahrenheit - 32) * 1.8;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Celsius zu Fahrenheit
|
|
||||||
public static double celsiusZuFahrenheit(double celsius) {
|
|
||||||
return (celsius * 1.8) + 32;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user