Reputation: 11
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.
I have a few questions I would like to understand:
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);
}
}
Upvotes: 1
Views: 427
Reputation: 155
Yes you are basically correct.
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.
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){..}
}
Upvotes: 2