Morgen!
Ich hätte da eine große Bitte bzw Frage.
Ich habe für die Schule ein "Programm" geschrieben welches Zahlen generiert und die generierte Zahl muss erraten werden. Ich habe ein paar zusätzliche Dinge gemacht die nicht gefragt waren.
z.B. > Sprachauswahl
> Tutorial
> eine Abfrage ob man nochmals "spielen" möchte
Da ich erst seit wenigen Monaten mit Programmieren zu tun habe ist es total unübersichtlich geworden:
(Achtung! Für erfahrene Programmierer sicher ein schmerzender Anblick!)
Das wär mein "kleines Programm".
Meine bitte wäre nun, ob mir jemand helfen könnte das ganze übersichtlicher und einfacher zu gestalten aber so das es ein totaler Anfänger auch noch versteht. Alles was ich bis jetzt so in Programmieren gelernt habe, habe ich hier angewand.
Hat jemand eine Idee wie man das ganze einfacher machen kann aber das ich es trotzdem noch verstehe?
mfg und hoffnung auf baldige Antwort,
wiesner95
Ich hätte da eine große Bitte bzw Frage.
Ich habe für die Schule ein "Programm" geschrieben welches Zahlen generiert und die generierte Zahl muss erraten werden. Ich habe ein paar zusätzliche Dinge gemacht die nicht gefragt waren.
z.B. > Sprachauswahl
> Tutorial
> eine Abfrage ob man nochmals "spielen" möchte
Da ich erst seit wenigen Monaten mit Programmieren zu tun habe ist es total unübersichtlich geworden:
(Achtung! Für erfahrene Programmierer sicher ein schmerzender Anblick!)
Java:
import java.util.*;
public class Zufallszahl{
public static void main(String[] args){
System.out.println("RANDOM NUMBER GENERATOR ");
System.out.println();
System.out.print("Do you want see the tutorial (yes/no)?: ");
Scanner tut=new Scanner(System.in);
String tutyn = tut.next();
System.out.println();
if(tutyn.equals("yes")){
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println(" TUTORIAL:");
System.out.println(" The following programm is going to generate a number between 1 and 100.");
System.out.println(" You have three tries too guess the generated number!");
System.out.println(" Have fun!");
System.out.println();
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.print("Please select the language (english/german)? ");
Scanner Sprache=new Scanner(System.in);
String mSprache = Sprache.next();
System.out.println();
System.out.println();
if(mSprache.equals("english")){
Scanner nochmals=new Scanner(System.in);
do{
int max=100;
int zufallszahl=(int)(Math.random()*max+1);
for(int a=2; a>-1; a--){
System.out.print("Please choose a number between 1 and 100: ");
Scanner zahl= new Scanner(System.in);
int x=zahl.nextInt();
if(x<zufallszahl){
System.out.println();
System.out.println("The number " + x + " is less than the generated number!");
if(a==0){
System.out.println("You haven't any tries!");
System.out.println();
System.out.println();
}
else{
System.out.print("You have still " + a + " tries!");
System.out.println();
System.out.println();
}
}
else{
if(x>zufallszahl){
System.out.println();
System.out.println("The number " + x + " is bigger than the generated number!");
if(a==0){
System.out.println("You haven't any tries!");
System.out.println();
System.out.println();
}
else{
System.out.print("You have still " + a + " tries!");
System.out.println();
System.out.println();
}
}
else{
System.out.println();
System.out.println("The generated number agrees with the input number!");
if(a==0){
System.out.println("You haven't any tries!");
System.out.println();
System.out.println();
}
else{
System.out.print("You have still " + a + " tries!");
System.out.println();
System.out.println();
}
}
}
}
System.out.println();
System.out.println("The generated number is " + zufallszahl + "!");
System.out.println();
System.out.println();
System.out.print("Do you want play again (yes/no)?: ");
}while( ( nochmals.next()).equals("yes"));
System.out.println();
System.out.println();
System.out.println(" Thanks, for using Wiesner-Systems!");
}
else{
if(mSprache.equals("german")){
Scanner nochmals=new Scanner(System.in);
do{
int max=100;
int zufallszahl=(int)(Math.random()*max+1);
for(int a=2; a>-1; a--){
System.out.print("Bitte geben Sie eine Zahl von 1 bis 100 ein: ");
Scanner zahl= new Scanner(System.in);
int x=zahl.nextInt();
if(x<zufallszahl){
System.out.println();
System.out.println("Die Zahl " + x + " ist kleiner als die gesuchte Zahl!");
if(a==0){
System.out.println("Sie haben keine Versuche mehr frei!");
System.out.println();
System.out.println();
}
else{
System.out.print("Sie haben noch " + a + " Versuche offen!");
System.out.println();
System.out.println();
}
}
else{
if(x>zufallszahl){
System.out.println();
System.out.println("Die Zahl " + x + " ist größer als die gesuchte Zahl!");
if(a==0){
System.out.println("Sie haben keine Versuche mehr frei!");
System.out.println();
System.out.println();
}
else{
System.out.print("Sie haben noch " + a + " Versuche offen!");
System.out.println();
System.out.println();
}
}
else{
System.out.println();
System.out.println("Die gesuchte Zahl stimmt mit der eingegebnen überein!");
if(a==0){
System.out.println("Sie haben keine Versuche mehr frei!");
System.out.println();
System.out.println();
}
else{
System.out.print("Sie haben noch " + a + " Versuche offen!");
System.out.println();
System.out.println();
}
}
}
}
System.out.println();
System.out.println("Die gesuchte Zahl war " + zufallszahl + "!");
System.out.println();
System.out.println();
System.out.print("Wollen sie nochmals (ja/nein)?: ");
}while( ( nochmals.next()).equals("ja"));
System.out.println();
System.out.println();
System.out.println(" Danke, dass sie Wiesner-Systems benutzt haben!");
}
else{
System.out.println("The input is incorrect.");
System.out.println("Please quit the programm and start it again!");
}
}
}
else{
if(tutyn.equals("no")){
System.out.print("Please select the language (english/german)? ");
Scanner Sprache=new Scanner(System.in);
String mSprache = Sprache.next();
System.out.println();
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
if(mSprache.equals("english")){
Scanner nochmals=new Scanner(System.in);
do{
int max=100;
int zufallszahl=(int)(Math.random()*max+1);
for(int a=2; a>-1; a--){
System.out.print("Please choose a number between 1 and 100: ");
Scanner zahl= new Scanner(System.in);
int x=zahl.nextInt();
if(x<zufallszahl){
System.out.println();
System.out.println("The number " + x + " is less than the generated number!");
if(a==0){
System.out.println("You haven't any tries!");
System.out.println();
System.out.println();
}
else{
System.out.print("You have still " + a + " tries!");
System.out.println();
System.out.println();
}
}
else{
if(x>zufallszahl){
System.out.println();
System.out.println("The number " + x + " is bigger than the generated number!");
if(a==0){
System.out.println("You haven't any tries!");
System.out.println();
System.out.println();
}
else{
System.out.print("You have still " + a + " tries!");
System.out.println();
System.out.println();
}
}
else{
System.out.println();
System.out.println("The generated number agrees with the input number!");
if(a==0){
System.out.println("You haven't any tries!");
System.out.println();
System.out.println();
}
else{
System.out.print("You have still " + a + " tries!");
System.out.println();
System.out.println();
}
}
}
}
System.out.println();
System.out.println("The generated number is " + zufallszahl + "!");
System.out.println();
System.out.println();
System.out.print("Do you want play again (yes/no)?: ");
}while( ( nochmals.next()).equals("yes"));
System.out.println();
System.out.println();
System.out.println(" Thanks, for using Wiesner-Systems!");
}
else{
if(mSprache.equals("german")){
Scanner nochmals=new Scanner(System.in);
do{
int max=100;
int zufallszahl=(int)(Math.random()*max+1);
for(int a=2; a>-1; a--){
System.out.print("Bitte geben Sie eine Zahl von 1 bis 100 ein: ");
Scanner zahl= new Scanner(System.in);
int x=zahl.nextInt();
if(x<zufallszahl){
System.out.println();
System.out.println("Die Zahl " + x + " ist kleiner als die gesuchte Zahl!");
if(a==0){
System.out.println("Sie haben keine Versuche mehr frei!");
System.out.println();
System.out.println();
}
else{
System.out.print("Sie haben noch " + a + " Versuche offen!");
System.out.println();
System.out.println();
}
}
else{
if(x>zufallszahl){
System.out.println();
System.out.println("Die Zahl " + x + " ist größer als die gesuchte Zahl!");
if(a==0){
System.out.println("Sie haben keine Versuche mehr frei!");
System.out.println();
System.out.println();
}
else{
System.out.print("Sie haben noch " + a + " Versuche offen!");
System.out.println();
System.out.println();
}
}
else{
System.out.println();
System.out.println("Die gesuchte Zahl stimmt mit der eingegebnen überein!");
if(a==0){
System.out.println("Sie haben keine Versuche mehr frei!");
System.out.println();
System.out.println();
}
else{
System.out.print("Sie haben noch " + a + " Versuche offen!");
System.out.println();
System.out.println();
}
}
}
}
System.out.println();
System.out.println("Die gesuchte Zahl war " + zufallszahl + "!");
System.out.println();
System.out.println();
System.out.print("Wollen sie nochmals (ja/nein)?: ");
}while( ( nochmals.next()).equals("ja"));
System.out.println();
System.out.println();
System.out.println(" Danke, dass sie Wiesner-Systems benutzt haben!");
}
else{
System.out.println("The input is incorrect.");
System.out.println("Please quit the programm and start it again!");
}
}
}
else{
System.out.println("The input is incorrect.");
System.out.println("Please quit the programm and start it again!");
}
}
}
}
Das wär mein "kleines Programm".
Meine bitte wäre nun, ob mir jemand helfen könnte das ganze übersichtlicher und einfacher zu gestalten aber so das es ein totaler Anfänger auch noch versteht. Alles was ich bis jetzt so in Programmieren gelernt habe, habe ich hier angewand.
Hat jemand eine Idee wie man das ganze einfacher machen kann aber das ich es trotzdem noch verstehe?
mfg und hoffnung auf baldige Antwort,
wiesner95