Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.frikk.oblig2;
- import java.io.File;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Scanner;
- class Main {
- static ArrayList<Legemiddel> legemidler = new ArrayList<Legemiddel>();
- static HashMap<String, Lege> leger = new HashMap<String, Lege>();
- static ArrayList<Resept> resepter = new ArrayList<Resept>();
- public static void main(String[] args) {
- lesFil("kuk.txt");
- for (Legemiddel l : legemidler) {
- System.out.println(l);
- }
- }
- public static void lesFil(String filnavn) {
- Scanner fil = null;
- try {
- fil = new Scanner(new File(filnavn));
- while(fil.hasNextLine()) {
- String header = fil.nextLine();
- if (header.startsWith("# Legemidler")) {
- while (true) {
- String linje = fil.nextLine();
- if (linje.startsWith("#")) {break;}
- String[] lmInfo = linje.split(", ");
- String navn = lmInfo[0].trim();
- String type = lmInfo[1].trim();
- double pris = Double.parseDouble(lmInfo[2].trim());
- double virkestoff = Double.parseDouble(lmInfo[3].trim());
- if (type == "a") {
- int styrke = Integer.parseInt(lmInfo[4].trim());
- legemidler.add(new PreparatA(navn, pris, virkestoff, styrke));
- }
- if (type == "b") {
- int styrke = Integer.parseInt(lmInfo[4].trim());
- legemidler.add(new PreparatB(navn, pris, virkestoff, styrke));
- }
- if (type == "b") {
- legemidler.add(new PreparatC(navn, pris, virkestoff));
- }
- }
- }
- if (header.startsWith("# Leger")) {
- while(true) {
- String linje = fil.nextLine();
- if (linje.startsWith("#")) {break;}
- String[] legeInfo = linje.split(", ");
- String navn = legeInfo[0].trim();
- int kontrollID = Integer.parseInt(legeInfo[0].trim());
- if (kontrollID == 0) {
- leger.put(navn, new Lege(navn));
- }
- else {
- leger.put(navn, new Spesialist(navn, kontrollID));
- }
- }
- }
- }
- } catch (Exception e) {
- //TODO: handle exception
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement