متيكو المدير والمشرف
المدير العام الجنس : عدد المساهمات : 590 تاريخ الميلاد : 02/11/1989 تاريخ التسجيل : 28/08/2009 العمر : 35 الموقع : www.matti-king.blogspot.com العمل/الترفيه : يشرف عالمنتدى ويدرس المزاج : تعبان | موضوع: java library writing to file الجمعة مايو 27, 2011 2:25 pm | |
| package app; import java.io.*; import java.util.ArrayList; import java.util.Scanner; import library.Book; import library.Magazine; import library.Movie; import library.Story; import library.customer;
public class WriteTextFile { public static void addnewbook () throws NumberFormatException, IOException { System.out.println("which section your item belong to: 1-book " +" "+ "2-story" +" "+ "3-Magazine " +" "+ "4-movie" +" "+ "5-customer "); BufferedReader userOption = new BufferedReader(new InputStreamReader(System.in)); float option = Float.parseFloat(userOption.readLine()); if (option == 1) { bookList(null); } else if (option == 2) { storyList(null); } else if(option==3) { magazineList(null); } else if(option==4) { movieList(null); } else if(option==5) { customers(null); } } public static ArrayList<Book> bookList(Book[] myBooks)throws IOException { ArrayList <Book> bb=new ArrayList<Book>(); String fileName = "MyFile.txt" ; FileWriter writer = new FileWriter( fileName, false); PrintWriter out=new PrintWriter(writer); System.out.println("to add new book fill the next form"); Scanner input=new Scanner(System.in); String Name; System.out.println("Enter your name"); Name=input.nextLine(); out.println(Name); String isbn; System.out.println("Enter the Isbn"); isbn=input.nextLine(); out.println(isbn); String auther; System.out.println("Enter the Auther"); auther=input.nextLine(); out.println(auther); String title; System.out.println("Enter the title"); title=input.nextLine(); out.println(title); String type; System.out.println("Enter the type"); type=input.nextLine(); out.println(type); String edition; System.out.println("Enter the Edition"); edition=input.nextLine(); out.println(edition); String year_pubilsh; System.out.println("Enter the Year of publish"); year_pubilsh=input.nextLine(); out.println(year_pubilsh); String date_borrowed; System.out.println("Enter the date of borrowed"); date_borrowed=input.nextLine(); out.println(date_borrowed); out.close(); System.out.println("press 7 to back to the main minue"); bb.add(new Book(title, auther, type ,edition, year_pubilsh, date_borrowed)); return bb; } public static ArrayList<Story> storyList(Story[] myStory)throws IOException { ArrayList <Story> ss=new ArrayList<Story>(); String fileName = "MyFile.txt" ; FileWriter writer = new FileWriter( fileName, false); PrintWriter out=new PrintWriter(writer); System.out.println("to add new book fill the next form"); Scanner input=new Scanner(System.in); String title; System.out.println("Enter the Title"); title=input.nextLine(); out.println(title); String userNumber; System.out.println("Enter the userNumber"); userNumber=input.nextLine(); out.println(userNumber); out.close(); System.out.println("press 7 to back to the main minue"); ss.add(new Story(title, userNumber)); return ss; } @SuppressWarnings("unused") public static ArrayList<Movie> movieList(Movie[] myMovie)throws IOException { ArrayList <Movie> mm=new ArrayList<Movie>(); Movie[] movies = new Movie[3]; String fileName = "MyFile.txt" ; FileWriter writer = new FileWriter( fileName, false); PrintWriter out=new PrintWriter(writer); System.out.println("to add new book fill the next form"); Scanner input=new Scanner(System.in); String Name; System.out.println("Enter the Name"); Name=input.nextLine(); out.println(Name); String Genre; System.out.println("Enter the Genre"); Genre=input.nextLine(); out.println(Genre); String Director; System.out.println("Enter the Director"); Director=input.nextLine(); out.println(Director); String Writer; System.out.println("Enter the Writer"); Writer=input.nextLine(); out.println(Writer); String Producer; System.out.println("Enter the Producer"); Producer=input.nextLine(); out.println(Producer); String Language; System.out.println("Enter the Language"); Language=input.nextLine(); out.println(Language); String Country; System.out.println("Enter the Country"); Country=input.nextLine(); out.println(Country); String Year_of_produce; System.out.println("Enter the Year_of_produce"); Year_of_produce=input.nextLine(); out.println(Year_of_produce); out.close(); System.out.println("press 7 to back to the main minue"); mm.add(new Movie(Name,Genre,Director,Writer,Producer,Language,Country,null)); return mm; } @SuppressWarnings("unused") public static ArrayList<Magazine> magazineList(Magazine[] myMagazine)throws IOException { ArrayList <Magazine> ma=new ArrayList<Magazine>(); Magazine[] magazine = new Magazine[2]; String fileName = "MATTI.txt"; FileWriter writer = new FileWriter( fileName, false); PrintWriter out=new PrintWriter(writer); System.out.println("to add new book fill the next form"); Scanner input=new Scanner(System.in); String title; System.out.println("Enter the Title"); title=input.nextLine(); out.println(title); String userNumber; System.out.println("Enter the userNumber"); userNumber=input.nextLine(); out.println(userNumber); out.close(); System.out.println("press 7 to back to the main minue"); ma.add(new Magazine(title, userNumber)); return ma; } @SuppressWarnings("unused") public static ArrayList<customer> customers(customer[] mycustomer)throws IOException { ArrayList <customer> cc=new ArrayList<customer>(); customer[] customers = new customer[3]; String fileName = "MyFile.txt" ; FileWriter writer = new FileWriter( fileName, false); PrintWriter out=new PrintWriter(writer); System.out.println("to add new book fill the next form"); Scanner input=new Scanner(System.in); String firstName; System.out.println("Enter the firstName"); firstName=input.nextLine(); out.println(firstName); String lastName; System.out.println("Enter the lastName"); lastName=input.nextLine(); out.println(lastName); String birthday; System.out.println("Enter the birthday"); birthday=input.nextLine(); out.println(birthday); int phone_number; System.out.println("Enter the phone_number"); phone_number=input.nextInt(); out.println(phone_number); System.out.println("press 7 to back to the main minue"); cc.add(new customer(firstName , lastName , null, phone_number)); out.close(); return cc; } } | |
|