Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.Scanner;
- public class Nummer14{
- public static void main(String[] args) {
- File text = new File("Fahrzeug.txt");
- Nummer14Auto auto = new Nummer14Auto("Grün", 4, true);
- Nummer14Fahrrad fahrrad = new Nummer14Fahrrad("Pink", 2, true);
- save(text, auto, fahrrad);
- read(text);
- updateAuto(text, fahrrad, auto, "Blau", 4, false);
- read(text);
- deleteFahrrad(text, auto);
- read(text);
- }
- public static void save(File text, Nummer14Auto auto, Nummer14Fahrrad fahrrad){
- try {
- FileWriter writer;
- writer = new FileWriter(text);
- writer.write(auto.toString() + "\n" + fahrrad.toString());
- writer.flush();
- writer.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public static void read(File text){
- if(text.exists()){
- try {
- Scanner sc = new Scanner(text);
- while(sc.hasNext()){
- System.out.print(sc.next() + " ");
- }
- sc.close();
- } catch (FileNotFoundException e1) {
- e1.printStackTrace();
- }
- System.out.println();
- }
- }
- public static void updateAuto(File text, Nummer14Fahrrad fahrrad, Nummer14Auto auto, String farbe, int räder, boolean benzin){
- auto.setFarbe(farbe);
- auto.setAnzahlDerRaeder(räder);
- auto.setBenzin(benzin);
- save(text, auto, fahrrad);
- }
- public static void updateFahrrad(File text, Nummer14Auto auto, Nummer14Fahrrad fahrrad ,String farbe, int räder, boolean rennrad){
- fahrrad.setFarbe(farbe);
- fahrrad.setAnzahlDerRaeder(räder);
- fahrrad.setRennrad(rennrad);
- save(text, auto, fahrrad);
- }
- public static void deleteAuto(File text, Nummer14Fahrrad fahrrad){
- try {
- FileWriter writer;
- writer = new FileWriter(text);
- writer.write(fahrrad.toString());
- writer.flush();
- writer.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public static void deleteFahrrad(File text, Nummer14Auto auto){
- try {
- FileWriter writer;
- writer = new FileWriter(text);
- writer.write(auto.toString());
- writer.flush();
- writer.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement