Comp Sci How to Structure a UML Diagram for a Basic Java Program?

  • Thread starter Thread starter clook
  • Start date Start date
  • Tags Tags
    Diagram Java
AI Thread Summary
To create a UML diagram for the Java program, focus on the single class, NameDate, which contains three string variables (firstNameString, middleNameString, lastNameString), two objects (todayDate and formattingSimpleDateFormat), and two methods (System.out.print and System.out.println). Since the program consists of only one class and one method, the UML diagram will be straightforward, represented as a box with the class name and its components listed inside. The simplicity of the program makes the diagram less complex, but it still serves the educational purpose of illustrating class structure. Overall, the task emphasizes understanding basic UML representation for Java programs.
clook
Messages
32
Reaction score
0
So I have to create a UML diagram for my program:
Code:
import java.util.*;
import java.text.*;

public class NameDate {


	public static void main(String[] args) {
  		// Input the first, middle, and last name
		// Display the name and the date.
		String firstNameString, middleNameString, lastNameString;
		
		//Create a Scanner object
		Scanner inputScanner = new Scanner(System.in);
		
		//Objects needed for date.
		Date todayDate = new Date();
		SimpleDateFormat formattingSimpleDateFormat=
			new SimpleDateFormat("MMMM dd yyyy");
		
		//Input the data
		System.out.print("Enter your first name  ");
		firstNameString = inputScanner.next();
		
		//middleNameString enter middle name.
		System.out.print("Enter your middle name  ");
		middleNameString = inputScanner.next();

		
		System.out.print("Enter your last name ");
		lastNameString = inputScanner.next();
		
		//Print out first, middle, and last name with date.  
		System.out.println("Hello" + " " + lastNameString + "," + " " + firstNameString + " " + middleNameString.substring(0,1) + "." + " " + "Today is" + " "
		+ formattingSimpleDateFormat.format(todayDate));
	}

}

My professor wants me to do it like so:

Class
Variables
Objects
Methods.

I came up with this but I'm not exactly sure I did it right.

NameDate
Variables
firstNameString
middleNameString
lastNameString
Objects
todayDate
formattingSimpleDateFormat
Methods
System.out.print
System.out.println
inputScanner
 
Physics news on Phys.org
You can't really do a UML diagram of this... it's just one class, with only one method. It'd be kind of boring.

- Warren
 
chroot said:
You can't really do a UML diagram of this... it's just one class, with only one method. It'd be kind of boring.

- Warren
yeah, but i only need to do a diagram for this class.

kind of unsure how to do it.
 
A diagram of one class is... a box. With a name in it. That's all.

- Warren
 

Similar threads

Replies
7
Views
2K
Replies
1
Views
2K
Replies
12
Views
2K
Replies
3
Views
6K
Replies
6
Views
3K
Back
Top