Army

Report a typo

You decide to recall the happy days of your childhood and play Heroes. Of course, you need an army.

Your task is to create objects: 5 Unit, 3 Knight, 1 General, 1 Doctor.

Don't forget to give them names!

class Unit {    
    String nameUnit;
    
    public Unit(String name){
        nameUnit = name;
    }
}

class Knight {
    String nameKnight;

    public Knight(String name){
        nameKnight = name;
    }
}

class General {
    String nameGeneral;
    
    public General(String name){
        nameGeneral = name;
    }
}

class Doctor {
    String nameDoctor;
    
    public Doctor(String name){
        nameDoctor = name;
    }
}
Write a program in Java 17
class Army {

public static void createArmy() {
// Create all objects here
}


// Don't change the code below
static class Unit {
static String nameUnit;
static int countUnit;

public Unit(String name) {
countUnit++;
nameUnit = name;

}
}

static class Knight {
static String nameKnight;
static int countKnight;

public Knight(String name) {
countKnight++;
nameKnight = name;

}
}

static class General {
static String nameGeneral;
static int countGeneral;

public General(String name) {
countGeneral++;
___

Create a free account to access the full topic