//
//
// Generated by StarUML(tm) Java Add-In
//
// @ Project : Untitled
// @ File Name : Royalty.java
// @ Date : 2016/9/5
// @ Author :
//
//
public interface Royalty {
public void getFed();
public void getDrink();
public void changeMood();
public void receiveCompliments();
public boolean getMood();
}
//
//
// Generated by StarUML(tm) Java Add-In
//
// @ Project : Untitled
// @ File Name : King.java
// @ Date : 2016/9/5
// @ Author :
//
//
public class King implements Royalty {
public boolean isDrunk;
public boolean isHungry = true;
public boolean isHappy;
public boolean complimentReceived;
@Override
public void getFed() {
isHungry = false;
}
@Override
public void getDrink() {
isDrunk = true;
}
@Override
public void changeMood() {
if(!isHungry && isDrunk)
isHappy = true;
if(complimentReceived)
isHappy = false;
}
@Override
public void receiveCompliments() {
complimentReceived = true;
}
@Override
public boolean getMood() {
return isHappy;
}
}
//
//
// Generated by StarUML(tm) Java Add-In
//
// @ Project : Untitled
// @ File Name : Queen.java
// @ Date : 2016/9/5
// @ Author :
//
//
public class Queen implements Royalty {
public boolean isDrunk = true;
public boolean isHungry;
public boolean isHappy;
public boolean isFlirty = true;
public boolean complimentReceived;
@Override
public void getFed() {
isHungry = false;
}
@Override
public void getDrink() {
isDrunk = true;
}
@Override
public void changeMood() {
if(complimentReceived && isFlirty && isDrunk)
isHappy = true;
}
@Override
public void receiveCompliments() {
complimentReceived = true;
}
@Override
public boolean getMood() {
return isHappy;
}
}
import java.util.List;
//
//
// Generated by StarUML(tm) Java Add-In
//
// @ Project : Untitled
// @ File Name : Servant.java
// @ Date : 2016/9/5
// @ Author :
//
//
public class Servant {
public String name;
public Servant(String name) {
this.name = name;
}
public void feed(Royalty royalty) {
royalty.getFed();
}
public void giveWine(Royalty royalty) {
royalty.getDrink();
}
public void giveCompliments(Royalty royalty) {
royalty.receiveCompliments();
}
public boolean checkIfYouuWillBeChanged(List tableGuests) {
boolean anotherDay = true;
for(Royalty r : tableGuests)
{
if(!r.getMood())
anotherDay = false;
}
return anotherDay;
}
}
import java.util.ArrayList;
import java.util.List;
public class App {
static Servant jenkins = new Servant("Jenkins");
static Servant travis = new Servant("Travis");
public static void main(String[] args) {
scenario(jenkins,1);
scenario(travis,0);
}
private static void scenario(Servant servant, int compliment) {
King k = new King();
Queen q = new Queen();
List guests = new ArrayList<>();
guests.add(k);
guests.add(q);
servant.feed(k);
servant.feed(q);
servant.giveWine(k);
servant.giveWine(q);
servant.giveCompliments(guests.get(compliment));
for(Royalty r : guests)
r.changeMood();
if(servant.checkIfYouuWillBeChanged(guests))
System.out.println(servant.name + " will live another day");
else
System.out.println("Poor " + servant.name + ". His days are numbered");
}
}
/* Jenkins will live another day Poor Travis. His days are numbered*/