Jag hinner tyvärr inte kommentera det jag gjorde under föreläsningen (eventuellt kan jag göra det i efterhand), men nedanför finns den programkod vi skrev -- OH-bilderna finns här.

import se.lth.cs.pt.io.*;
import java.util.*;

class Account {

    private double balance = 10;    // attribut
    private int accountNumber;

    public Account  (int accountNumber) {     // konstruktor
        // körs när kontot skapas
        balance = 0;
        this.accountNumber = accountNumber;
    }

    public int getAccountNumber() {
        return accountNumber;
    }

    public double deposit(double amount) {   // metod
        if (amount >= 0) {
            balance += amount;
            return amount;
        }
        return 0;
    }

    public double withdraw(double amount) {
        if (amount < 0) {
            return 0;
        }
        if (amount > balance) {
            amount = balance;
        }
        balance -= amount;
        return amount;
    }

    public double getBalance() {
        return balance;
    }
}

class Bank {

    private List accounts;
    private double noAmount = Double.NEGATIVE_INFINITY;

    public Bank  () {
        accounts = new ArrayList();
    }

    public List getBigAccounts(double limit) {
        List found = new ArrayList();
        for (Account acc : accounts) {
            if (acc.getBalance() >= limit) {
                found.add(acc);
            }
        }
        return found;
    }

    public List allAccounts() {
        return getBigAccounts(0);
    }

    public boolean createAccount(int accNo) {
        if (this.hasAccount(accNo)) {
            return false;
        }
        accounts.add(new Account(accNo));
        return true;
    }

    public boolean hasAccount(int accNo) {
        if (getAccount(accNo) != null) {
            return true;
        }
        return false;
    }

    public double deposit(int accNo, double amount) {
        if (!hasAccount(accNo)) {
            return 0;
        }
        Account acc = getAccount(accNo);
        return acc.deposit(amount);
    }

    private Account getAccount(int accNo) {
        for (Account acc : accounts) {
            if (acc.getAccountNumber() == accNo) {
                return acc;
            }
        }
        return null;
    }

    public double getBalance(int accNo) {
        if (!hasAccount(accNo)) {
            return noAmount;
        }
        return getAccount(accNo).getBalance();
    }

    public double withdraw(int accNo, double amount) {
        Account acc = getAccount(accNo);
        if (acc == null) {
            return noAmount;
        }
        return acc.withdraw(amount);
    }
}


class MainBanking {

    public static void main(String[] args) {
        new MainBanking().run();
    }

    void run() {
        Bank bank = new Bank();
        if (bank.createAccount(Keyboard.nextInt("Ange kontonummer: "))) {
            System.out.println("OK");
        } else {
            System.out.println("Kunde inte skapa konto");
        }

        List bigAccs = bank.getBigAccounts(100000);
        bigAccs.clear();

        List allAccs = bank.allAccounts();
        for (Account acc : allAccs) {
            System.out.println(acc.getAccountNumber());
        }
        allAccs.clear();
        
        
    }
}

class Immutables {

    public static void main(String[] args) {
        new Immutables().run();
    }

    void run() {
        Person p = new Person("Agne");
        String name = p.getName();
        name += "ta";
        System.out.println(name);
        System.out.println(p.getName());

        if (p.getName() == "Agne") {
            System.out.println("Samma");
        } else {
            System.out.println("Inte samma");
        }
    }
}

class Person {

    private String name;

    public Person  (String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }            
}


class Geometry {

    public static void main(String[] args) {
        new Geometry().run();
    }

    void run() {
        Point p1 = new Point(1, 3);
        Point p2 = new Point(3, 1.2);
        Circle c1 = new Circle(p2, 3);
        // System.out.println(distanceBetween(p1, p2));
        System.out.println(p1.distanceTo(p2));
        System.out.println(p1.distanceTo(5, 5.5));
        if (c1.covers(p1)) {
            System.out.println("Täcker");
        } else {
            System.out.println("Täcker inte");
        }
        if (p1.inside(c1)) {
            System.out.println("Innanför");
        } else {
            System.out.println("Inte innanför");
        }
    }
}

class Point {

    private double x, y;

    public Point  (double x, double y) {
        this.x = x;
        this.y = y;
    }

    public Point  (Point other) {
        this(other.x, other.y);
    }

    public Point  () {
        this(0, 0);
    }

    public double distanceTo(Point other) {
        return distanceTo(other.x, other.y);
    }

    public double distanceTo(double x, double y) {
        double dx = this.x - x;
        double dy = this.y - y;
        return Math.sqrt(dx * dx + dy * dy);
    }

    public boolean inside(Circle c) {
        return c.covers(this);
    }
}

class Circle {

    private Point midPoint;
    private double radius;

    public Circle  (Point midPoint, double radius) {
        this.midPoint = midPoint;
        this.radius = radius;
    }

    public boolean covers(Point p) {
        return p.distanceTo(midPoint) <= radius;
    }
}