Guest User

Untitled

a guest
May 28th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. public class Telefonlist{
  4.     Scanner inmat=new Scanner(System.in);
  5.     public void matain(LinkedList lista){
  6.     System.out.print("Mata in namn: ");
  7.     String namn=inmat.next();
  8.     System.out.print("Mata in telefon: ");
  9.     String telefon=inmat.next();
  10.     Person temp=new Person(namn,telefon);
  11.     lista.add(temp);
  12.     }
  13.  
  14.     public void spara(LinkedList lista){
  15.     try
  16.     {
  17.         FileWriter fw=new FileWriter("tele.txt");
  18.         BufferedWriter bw=new BufferedWriter(fw);
  19.         PrintWriter utfil=new PrintWriter(bw);
  20.         for(int i=0;i<lista.size();i++)
  21.         {
  22.     Person temp=(Person)lista.get(i);
  23.     String namn=temp.hämtaNamn();
  24.     String telefonnr=temp.hämtaNummer();
  25.     utfil.println(namn + "\t" + telefonnr);
  26.         }
  27.         utfil.close();
  28.         System.out.println("Listan sparad");
  29.     }
  30.     catch(IOException e){
  31.         System.out.println("Det misslyckades");
  32.     }
  33.     }
  34. }
Add Comment
Please, Sign In to add comment