Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.83 KB | None | 0 0
  1. package me.frikk.oblig2;
  2.  
  3. import java.io.File;
  4. import java.util.ArrayList;
  5. import java.util.HashMap;
  6. import java.util.Scanner;
  7.  
  8. class Main {
  9.     static ArrayList<Legemiddel> legemidler = new ArrayList<Legemiddel>();
  10.     static HashMap<String, Lege> leger = new HashMap<String, Lege>();
  11.     static ArrayList<Resept> resepter = new ArrayList<Resept>();
  12.     public static void main(String[] args) {
  13.         lesFil("kuk.txt");
  14.        
  15.         for (Legemiddel l : legemidler) {
  16.             System.out.println(l);
  17.         }
  18.     }
  19.  
  20.     public static void lesFil(String filnavn) {
  21.         Scanner fil = null;
  22.        
  23.         try {
  24.             fil = new Scanner(new File(filnavn));
  25.  
  26.             while(fil.hasNextLine()) {
  27.                 String header = fil.nextLine();
  28.  
  29.                 if (header.startsWith("# Legemidler")) {
  30.                     while (true) {
  31.                         String linje = fil.nextLine();
  32.                         if (linje.startsWith("#")) {break;}
  33.                        
  34.                         String[] lmInfo = linje.split(", ");
  35.                         String navn = lmInfo[0].trim();
  36.                         String type = lmInfo[1].trim();
  37.                         double pris = Double.parseDouble(lmInfo[2].trim());
  38.                         double virkestoff = Double.parseDouble(lmInfo[3].trim());
  39.  
  40.                         if (type == "a") {
  41.                             int styrke = Integer.parseInt(lmInfo[4].trim());
  42.                             legemidler.add(new PreparatA(navn, pris, virkestoff, styrke));
  43.                         }
  44.  
  45.                         if (type == "b") {
  46.                             int styrke = Integer.parseInt(lmInfo[4].trim());
  47.                             legemidler.add(new PreparatB(navn, pris, virkestoff, styrke));
  48.                         }
  49.  
  50.                         if (type == "b") {
  51.                             legemidler.add(new PreparatC(navn, pris, virkestoff));
  52.                         }
  53.                     }
  54.                 }
  55.  
  56.                 if (header.startsWith("# Leger")) {
  57.                     while(true) {
  58.                         String linje = fil.nextLine();
  59.                         if (linje.startsWith("#")) {break;}
  60.  
  61.                         String[] legeInfo = linje.split(", ");
  62.                         String navn = legeInfo[0].trim();
  63.                         int kontrollID = Integer.parseInt(legeInfo[0].trim());
  64.  
  65.                         if (kontrollID == 0) {
  66.                             leger.put(navn, new Lege(navn));
  67.                         }
  68.  
  69.                         else {
  70.                             leger.put(navn, new Spesialist(navn, kontrollID));
  71.                         }
  72.                     }
  73.                 }
  74.  
  75.             }
  76.         } catch (Exception e) {
  77.             //TODO: handle exception
  78.         }
  79.     }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement