Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static ArrayList<Bil> filleser(String filnavn){
- String linje = "";
- ArrayList<Bil> bilene = new ArrayList<Bil>();
- try{
- BufferedReader lesFil = new BufferedReader(new FileReader(filnavn));
- while((linje = lesFil.readLine()) != null){
- String[] split = linje.split(" ");
- String type = split[0];
- String ord = split[1];
- double ord2 = 0;
- double ord3 = 0;
- int ord4 = 0;
- if(split.length > 2){
- ord2 = Double.parseDouble(split[2]);
- } if(split.length > 3){
- ord3 = Double.parseDouble(split[3]);
- } if (split.length > 4){
- ord4 = Integer.parseInt(split[4]);
- }
- if(type.equals("BIL")){
- Bil bil = new Bil(split[0], ord);
- bilene.add(bil);
- } else if (type.equals("EL")){
- Elbiler bil = new Elbiler(type, ord, ord2);
- bilene.add(bil);
- } else if (type.equals("FOSSIL")){
- Fossilbiler bil = new Fossilbiler(type, ord, ord2);
- bilene.add(bil);
- } else if (type.equals("LASTEBIL")){
- Lastebiler bil = new Lastebiler(type, ord, ord3, ord2);
- bilene.add(bil);
- } else if (type.equals("PERSONBIL")){
- Personbiler bil = new Personbiler(type, ord, ord2, ord4);
- bilene.add(bil);
- } else {
- System.out.println("Error, ikke gyldig bil.");
- }
- }
- lesFil.close();
- }
- catch(Exception e){
- System.out.println("Error: Noe galt med fil eller no'.");
- System.exit(0);
- }
- return bilene;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement