Answers for "uml diagram"

C++
0

uml diagram in java example

public class Person {
    private String name;
    private int age;

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

    public void printPerson() {
        System.out.println(this.name + ", age " +   this.age + " years");
    }

    public String getName() {
        return this.name;
    }
}
Posted by: Guest on February-23-2021
0

uml diagram

#include <utility>
#include <vector>

class Fireable {
public:
    virtual void fire() = 0;
};

class Employee : public Fireable{
    Employee() = default;
    std::string name;
protected:
    explicit Employee(std::string  name):name{name}{};
public:
    const std::string &getName() const {
        return name;
    }
    double payOwed(){
        return 0.0;
    }

    void fire() override {
        std::cout << "You are fired!" << std::endl;
    }
};

class Manager : public Employee {
    int hoursWorked{0};
    double payRate{0.0};
public:
    Manager(int hours, double rate,const std::string &name):hoursWorked{hours}, payRate{rate}, Employee(name){
        std::cout << "in the employee constructor" << std::endl;
    }
    double payOwed(){
        return hoursWorked * payRate;
    }
};

int main() {
    Employee *p = new Manager(10,22.5,"john");
    std::cout << p->getName() << " is owed " << p->payOwed() << std::endl;
    std::vector<Fireable*> firable;
    firable.push_back(new Manager(12,25.6,"Bill"));
    for(auto f : firable){
        f->fire();
    }
    return 0;
}
Posted by: Guest on October-14-2021

Browse Popular Code Answers by Language