Questions about creating UML Class diagram from Java program – default constructor? Are there no attributes in this example?

huangapple go评论88阅读模式
英文:

Questions about creating UML Class diagram from Java program - default constructor? Are there no attributes in this example?

问题

以下是翻译好的内容:

我有一个课程,在这个课程中,我必须为下面的程序手动创建一个UML图。为了更好地理解,我在Eclipse中使用ObjectAid自动生成了一个UML图。

我有几个问题希望能理解:

  1. 在类、属性和方法这三个部分中,为什么“PayrollDialog()”被包括在方法部分?是因为应该始终包括默认构造函数吗?
  2. 是不是真的不应该在方法部分列出JOptionPane.showInputDialog?为什么不列出?我问这个问题是因为我注意到没有包括获取用户名、工作小时数和支付率。
  3. 在这个程序的UML中真的没有要列出的属性吗?我认为是正确的,因为它们没有在public class PayrollDialog下列出。

这个程序列出的UML图真的准确吗?如果不准确,应该是什么样的?我很难相信作业会这么简单。

英文:

I have a class where I have to manually create a UML diagram for the program below. In order to understand better, I automatically created a UML diagram in Eclipse with ObjectAid.
Questions about creating UML Class diagram from Java program – default constructor? Are there no attributes in this example?

I have a few questions I would like to understand:

  1. Of the three sections class, attributes, and methods, why is "PayrollDialog()" included in the methods section? Is it because you should always include the default constructor?
  2. Are JOptionPane.showInputDialog really not considered for the methods section? Why not? I ask because I notice getting the user name, hours worked, and pay rate are not included.
  3. Are there really no attributes to be listed in the UML for this program? I think this is correct because they are not listed under the public class PayrollDialog.

Is the UML diagram listed really accurate for this program? If not, what should it look like? I find it hard to believe the assignment is that simple.

import javax.swing.JOptionPane;

/**
 4  * This program demonstrates using dialogs
 * with JOptionPane.
 */

public class PayrollDialog
{

	public static void main(String[] args)
	{
		String inputString;     // For reading input
		String name;            // The user's name
		int hours;              // The number of hours worked
		double payRate;         // The user's hourly pay rate
		double grossPay;        // The user's gross pay

		// Get the user's name.
		name = JOptionPane.showInputDialog("What is " +
				"your name? ");

		// Get the hours worked.
		inputString =
				JOptionPane.showInputDialog("How many hours " +
						"did you work this week? ");

		// Convert the input to an int.
		hours = Integer.parseInt(inputString);

		// Get the hourly pay rate.
		inputString =
				JOptionPane.showInputDialog("What is your " +
						"hourly pay rate? ");


		// Convert the input to a double.
		payRate = Double.parseDouble(inputString);

		// Calculate the gross pay.
		grossPay = hours * payRate;

		// Display the results.
		JOptionPane.showMessageDialog(null, "Hello " +
				name + ". Your gross pay is $" +
				grossPay);

		// End the program.
		System.exit(0);
	}
}

答案1

得分: 2

  1. 是的,你基本上是正确的。

  2. JOptionPane没有出现在类图中,因为它位于 javax.swing.JOptionPane 中,并且它没有作为你的PayrollDialog类的属性/属性或方法在全局范围内声明。

  3. 根据你的源代码,没有声明全局属性/属性。

例如

class PayrollDialog{
   static JFrame f; // 这将出现在UML中作为属性
   public static void main(String[] args){..}
}
英文:
  1. Yes you are basically correct.

  2. JOptionPane is not listed in the Class Diagram because it is found in javax.swing.JOptionPane and its not globally declared as property/attribute or method of your PayrollDialog class.

  3. Based on your source code, there are no global properties/attribute declared.

For example

class PayrollDialog{
   static JFrame f; // this would appear as property in UML
   public static void main(String[] args){..}
}

huangapple
  • 本文由 发表于 2020年10月12日 13:25:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/64312126.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定