Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileWriter;
  4. import java.io.IOException;
  5. import java.util.Scanner;
  6.  
  7. public class Nummer14{
  8. public static void main(String[] args) {
  9. File text = new File("Fahrzeug.txt");
  10.  
  11. Nummer14Auto auto = new Nummer14Auto("Grün", 4, true);
  12. Nummer14Fahrrad fahrrad = new Nummer14Fahrrad("Pink", 2, true);
  13.  
  14. save(text, auto, fahrrad);
  15.  
  16. read(text);
  17.  
  18. updateAuto(text, fahrrad, auto, "Blau", 4, false);
  19.  
  20. read(text);
  21.  
  22. deleteFahrrad(text, auto);
  23.  
  24. read(text);
  25.  
  26. }
  27. public static void save(File text, Nummer14Auto auto, Nummer14Fahrrad fahrrad){
  28. try {
  29. FileWriter writer;
  30. writer = new FileWriter(text);
  31. writer.write(auto.toString() + "\n" + fahrrad.toString());
  32.  
  33. writer.flush();
  34. writer.close();
  35. } catch (IOException e) {
  36. e.printStackTrace();
  37. }
  38. }
  39. public static void read(File text){
  40. if(text.exists()){
  41. try {
  42. Scanner sc = new Scanner(text);
  43.  
  44. while(sc.hasNext()){
  45. System.out.print(sc.next() + " ");
  46. }
  47.  
  48. sc.close();
  49.  
  50. } catch (FileNotFoundException e1) {
  51. e1.printStackTrace();
  52. }
  53. System.out.println();
  54. }
  55. }
  56. public static void updateAuto(File text, Nummer14Fahrrad fahrrad, Nummer14Auto auto, String farbe, int räder, boolean benzin){
  57. auto.setFarbe(farbe);
  58. auto.setAnzahlDerRaeder(räder);
  59. auto.setBenzin(benzin);
  60. save(text, auto, fahrrad);
  61. }
  62. public static void updateFahrrad(File text, Nummer14Auto auto, Nummer14Fahrrad fahrrad ,String farbe, int räder, boolean rennrad){
  63. fahrrad.setFarbe(farbe);
  64. fahrrad.setAnzahlDerRaeder(räder);
  65. fahrrad.setRennrad(rennrad);
  66. save(text, auto, fahrrad);
  67. }
  68. public static void deleteAuto(File text, Nummer14Fahrrad fahrrad){
  69. try {
  70. FileWriter writer;
  71. writer = new FileWriter(text);
  72. writer.write(fahrrad.toString());
  73.  
  74. writer.flush();
  75. writer.close();
  76. } catch (IOException e) {
  77. e.printStackTrace();
  78. }
  79. }
  80. public static void deleteFahrrad(File text, Nummer14Auto auto){
  81. try {
  82. FileWriter writer;
  83. writer = new FileWriter(text);
  84. writer.write(auto.toString());
  85.  
  86. writer.flush();
  87. writer.close();
  88. } catch (IOException e) {
  89. e.printStackTrace();
  90. }
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement