【问题标题】:UML diagram for main class主类的UML图
【发布时间】:2017-02-27 06:26:31
【问题描述】:

如何为主类制作 UML 图?我不知道哪个是属性和操作。我不知道哪个属性和操作是公共的还是私有的。这是代码:

public class Assignment {
    public static void main(String[] args) {
        double pi = 3.14159;
        int radius;
        Area Ar1 = new Area();
        Scanner scanner = new Scanner(System.in);

        System.out.println("Choose which shape you want to calculate; \n1 Parallelogram \n2 Circle");
        Ar1.setShape(scanner.nextInt());

        switch (Ar1.getShape()){
            case 1:
                System.out.println("Insert length");
                Ar1.setLength(scanner.nextInt());

                System.out.println("Insert width");
                Ar1.setWidth(scanner.nextInt());

                System.out.println("Area: " + Ar1.getLength() * Ar1.getWidth());
                break;

            case 2:
                System.out.println("Insert radius");
                radius = scanner.nextInt();

                System.out.println("Area: " + pi * (radius * radius));
                break;

            default:
                System.out.println("ERROR: Please choose something else");
        }
    }
}

【问题讨论】:

  • 没有任何操作。它没有属性。这不是一堂课。你不需要画任何东西。
  • 您可能希望在UML sequence diagram 中将主类显示为演员(生命线),而不是UML 类图

标签: java uml


【解决方案1】:

我已经有一段时间没有使用 UML 了,即使我使用它时也不是很严格。

由于类没有属性并且方法是静态的,您可以只添加类名和方法名(除非您不计算 UML 中的静态方法)。

【讨论】:

    猜你喜欢
    • 2012-03-21
    • 1970-01-01
    • 2015-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多