Skip to content
Snippets Groups Projects
Commit d10591c2 authored by Børge Haugset's avatar Børge Haugset
Browse files

Etter forelesning

parent bb7c32b3
No related branches found
No related tags found
No related merge requests found
package uke2;
public class KaffeMater {
public void serverKaffe(Person person) {
while (person.nokKaffe() == false) {
System.out.println("KaffeMater mater "+person.getNavn());
person.drikkKaffe();
}
}
public KaffeMater() {
System.out.println("Vi lager en KM!");
}
public static void main(String[] args) {
KaffeMater kaffeMater = new KaffeMater();
Person person = new Person("Bernt");
System.out.println("Nok kaffe: "+person.nokKaffe());
kaffeMater.serverKaffe(person);
System.out.println("Nok kaffe: "+person.nokKaffe());
}
}
package uke2;
public class MiniKafe {
Person person;
KaffeMater kaffeMater;
public MiniKafe() {
this.kaffeMater = new KaffeMater();
}
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
public void serverPerson() {
if (this.person != null){
this.kaffeMater.serverKaffe(this.person);
}
}
public static void main(String[] args) {
MiniKafe mk = new MiniKafe();
mk.serverPerson();
Person person = new Person("Ada");
mk.setPerson(person);
mk.serverPerson();
Person person2 = new Person("Børge");
mk.setPerson(person2);
mk.serverPerson();
}
}
......@@ -20,9 +20,12 @@ public class Person {
public String getNavn() {
return navn;
}
public void drikkKaffe() {
var variabelnavn = "34";
this.kopperIntatt += 1;
System.out.println(this.getNavn()+" har drukket kopp "+this.kopperIntatt);
}
......@@ -33,11 +36,5 @@ public class Person {
person.drikkKaffe();
System.out.println("Nok kaffe: "+person.nokKaffe());
Person person2 = new Person("Frank");
person.drikkKaffe();
person.drikkKaffe();
person.drikkKaffe();
person.drikkKaffe();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment