Back to all lessons


Lesson 12

Three stories

Task A

Make all classess, methods, fields, to execute main method.


public class Main {
    public static void main(String[] args) {
        
        String name = "Tony";
        String familyName = "Stark";
        Billionaire tonyStark = new Billionaire(name, familyName);
        tonyStark.setMoney(1000000000000l);

        Enemy enemy = new Enemy("Justin Hammer");
        enemy.makeEvilIntroduction(); // Prints: "I'm [name]!", where name is a property
        enemy.attack(tonyStark); // 50% of chances, that tonyStark has been attacked successfully

        if (tonyStark.isInDanger()) { // If attack is a success
            IronMan ironMan = new IronMan(tonyStark);
            ironMan.attack(enemy);  // Prints: "[name] defeated!", where name is a name of enemy
            ironMan.printNameOfOwner(); // Prints: "Iron Man wins"
        } else {
            tonyStark.goParty(); // Prints: "Party time!"
        }
    }
}
                
Task B

Make all classess, methods, fields, to execute main method.

Note: Horcruxes are like health points.


public class Main {
    public static void main(String[] args) {
        
        int amountOfHorcruxes = 8;
        Voldemort youKnowWho = new Voldemort(amountOfHorcruxes);

        String name = "Harry";
        String familyName = "Potter";
        RegularPerson harry = new RegularPerson(name, familyName);
        youKnowWho.killLily(); // Prints something sad

        Dumbledore albus = new Dumbledore();
        Wizard harryWizard = albus.youAreWizard(harry); // Prints "You are a wizard, Harry"

        while (youKnowWho.isAlive()) { // If Voldemort has any Horcrux
            harryWizard.destroyHorcruxOf(youKnowWho); // Decrease amount of Horcruxes
            harryWizard.tryToDefeat(youKnowWho); // Success, if Voldemort has no Horcruxes
        }

        System.out.println("Happy ending");
    }
}
Task C

Make all classess, methods, fields, to execute main method.


public class Main {
    public static void main(String[] args) {
    
        Baby unknownBaby = new Baby("Geralt");
        Witcher vesemir = new Witcher("Vesemir");
        Witcher geralt = vesemir.trialOfTheGrasses(unknownBaby);
        while (!geralt.readyToBattle()) {
            vesemir.train(geralt);
        }
        while (!geralt.isPowerful()) {
            Monster monster = Plot.generateRandomMonster();
            geralt.kill(monster);
        }
        Place place = new Place("Kaer Morhen");
        EpicBattle battle = new EpicBattle();
        battle.setWhere(place);
        battle.addEnemy(new Enemy("Imlerith"));
        battle.addEnemy(new Enemy("Caranthir Ar-Feiniel"));
        battle.addHero(vesemir);
        battle.addHero(geralt);
        battle.start(); // List all enemies and hereos
        battle.end(); // Vesemir dies 
    }
}