טוב זאת בערך התוכנה:
בכל מקרה כמו שאתם בטח רואים אני מנסה להכניס את הנתנונים שהשמתמש מביא לקובץ טקסט ואחרי זה בפתיחה הבאה של התוכנה לקרוא אותם. (זה לא מה שניסיתי לכתוב שם סתם ניסיתי שזה יכתוב בטקסט בלה) בכל מקרה זה יוצר קובץ טקסט כמו שאני רוצה אבל הוא ריקקוד:import java.util.Scanner; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.Writer; public class Locker { public String readTextFile(String fileName) { String returnValue = ""; FileReader file = null; String line = ""; try { file = new FileReader(fileName); BufferedReader reader = new BufferedReader(file); while ((line = reader.readLine()) != null) { returnValue += line + "\n"; } } catch (FileNotFoundException e) { throw new RuntimeException("File not found"); } catch (IOException e) { throw new RuntimeException("IO Error occured"); } finally { if (file != null) { try { file.close(); } catch (IOException e) { e.printStackTrace(); } } } return returnValue; } public void writeTextFile(String fileName, String s) { FileWriter output = null; try { output = new FileWriter(fileName); BufferedWriter writer = new BufferedWriter(output); writer.write(s); } catch (IOException e) { e.printStackTrace(); } finally { if (output != null) { try { output.close(); } catch (IOException e) { e.printStackTrace(); } } } } public static void main(String[] args){ Locker myFile = new Locker(); String input = myFile.readTextFile("Locker.txt"); System.out.println(input); myFile.writeTextFile("LockerInfo.txt", input); int i= 0 ; // information about history int g= 0 ; // information about math int h = 1; // starting over value while (h==1) { Scanner console = new Scanner(System.in); System.out.println("Welcome to Locker, what would u like to do?"); System.out.println("to check your locker, press 2."); System.out.println("to change your locker informtion, press 1"); int active = console.nextInt(); if (active==1){ System.out.println("please choose your subject"); System.out.println("for history press 1, for math press 2"); // subject choosing int x = console.nextInt(); if (x==1){ System.out.println("does history in the locker?"); System.out.println("if its in the locker press 1, if its not press 2"); int in_out_history = console.nextInt(); // in or out? if(in_out_history==1){ boolean hi = true; i = 1 ; System.out.println("history is in the locker, saved successfuly"); System.out.println("math is not in the locker, saved successfuly"); System.out.println("would u like to start over? press 1 for no or 2 for yes");//start over h = console.nextInt(); } else if(in_out_history==2){ boolean hi= false; i=2; System.out.println("history is not in the locker, saved successfuly"); System.out.println("math is not in the locker, saved successfuly"); System.out.println("would u like to start over? press 1 for no or 2 for yes");//start over h = console.nextInt(); } else System.out.println("you didnt entered a viald number"); } else if (x==2){ System.out.println("does math in the locker?"); System.out.println("if its in the locker press 1, if its not press 2"); int in_out_math = console.nextInt(); // in or out? if(in_out_math==1){ boolean math_locker = true; g = 1; System.out.println("math is in the locker, saved successfuly"); System.out.println("math is in the locker, saved successfuly"); System.out.println("would u like to start over? press 1 for no or 2 for yes");//start over h = console.nextInt(); } else if(in_out_math==2){ boolean math_locker = false; g = 2; System.out.println("math is not in the locker, saved successfuly"); System.out.println("would u like to start over? press 1 for no or 2 for yes");//start over h = console.nextInt(); } else System.out.println("you didnt entered a viald number"); } else System.out.println("you didnt entered a viald number"); } if (active==2){ if(i==1){ System.out.println("history = in the locker"); } else if(i==2){ System.out.println("history = not in the locker"); } else if(i==0){ System.out.println("History = didnt typed in"); } if(g==1){ System.out.println("Math = in the locker"); } else if(g==2){ System.out.println("Math = not in the locker"); } else if(g==0){ System.out.println("Math = didnt typed in"); } //situation in locker } else { h-- ; //start again } class MyFile { } } } }
יש לכם מושג מה לעשות?



ציטוט ההודעה

