Java UML2.0序列图深度
我正在做我的期中作业,为一个简单的java程序创建一个序列图。然而,我遇到了一个问题,我无法决定将哪个元素放在一个图中,以及忽略哪个元素。如果可以帮助回答这个问题,我将发布一个JAVA代码Java UML2.0序列图深度,java,uml,sequence,diagram,sequence-diagram,Java,Uml,Sequence,Diagram,Sequence Diagram,我正在做我的期中作业,为一个简单的java程序创建一个序列图。然而,我遇到了一个问题,我无法决定将哪个元素放在一个图中,以及忽略哪个元素。如果可以帮助回答这个问题,我将发布一个JAVA代码 public class TestPOS { public static void main(String[] args) { // POST 객체를 준비 Store store = new Store(); ProductCatalog catalog = new ProductC
public class TestPOS {
public static void main(String[] args) {
// POST 객체를 준비
Store store = new Store();
ProductCatalog catalog = new ProductCatalog();
catalog.addSpec(1, new ProductSpec(1, "pencil", 1000));
catalog.addSpec(2, new ProductSpec(2, "eraser", 500));
catalog.addSpec(3, new ProductSpec(3, "fountain pen", 50000));
POST post = new POST(store, catalog);
// 첫 번째 판매
post.enterItem(1, 12);
post.enterItem(2, 4);
post.enterItem(3, 1);
post.makePayment();
post.endSale();
// 두 번째 판매
post.enterItem(1, 2);
post.enterItem(2, 1);
post.makePayment();
post.endSale();
// 출력을 보여주어 이해를 돕기위한 코드
for (Sale sale : store.completedSales) {
System.out.println(sale.getDate());
sale.printLineItems();
System.out.println("total = " + sale.getTotal());
}
}
}
这是它调用enterItem()、makePayment()和endSale()的主要位置。任务是为上述三个功能创建序列图。我将在下面发布每个课程
-----------------------------------------------------------
import java.util.Date;
public class POST {
private Store store;
private ProductCatalog catalog;
private Sale sale = null;
public POST(Store store, ProductCatalog catalog) {
this.store = store;
this.catalog = catalog;
}
public void enterItem(int upc, int qty) {
if (sale == null) {
Date date = new Date(System.currentTimeMillis());
sale = new Sale(date);
}
ProductSpec s = catalog.spec(upc);
sale.makeLineItem(s, qty);
}
public void makePayment() {
if (sale != null) sale.makePayment();
}
public void endSale() {
store.addCompleteSale(sale);
sale = null;
}
}
-----------------------------------------------------------
import java.util.ArrayList;
public class Store {
protected ArrayList<Sale> completedSales = null;
public Store() {
completedSales = new ArrayList<Sale>();
}
public void addCompleteSale(Sale sale) {
completedSales.add(sale);
}
}
-----------------------------------------------------------
import java.util.ArrayList;
import java.util.Date;
public class Sale {
private Date date;
private ArrayList<SalesLineItem> lineItem = null;
private Payment payment = null;
public Sale(Date date)
{
this.date = date;
lineItem = new ArrayList<SalesLineItem>();
}
public void makeLineItem(ProductSpec s, int qty) {
SalesLineItem item = new SalesLineItem(s, qty);
lineItem.add(item);
}
public int getTotal() {
int total = 0;
for (SalesLineItem item : lineItem) {
total += item.getSubTotal();
}
return total;
}
public void makePayment() {
int total = this.getTotal();
payment = new Payment(total);
}
// 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음
public Date getDate() {
return date;
}
// 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음
public void printLineItems() {
for (SalesLineItem item : lineItem) {
System.out.println("upc : " + item.getItemUpc() +", name : " + item.getItemName() + ", price : "
+ item.getItemPrice() + ", quantity : " + item.getQuantity());
}
}
}
-----------------------------------------------------------
public class Payment {
private int amount;
public Payment(int amount) {
this.amount = amount;
}
// 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음
public int getAmount() {
return amount;
}
}
-----------------------------------------------------------
public class SalesLineItem {
private int quantity;
private ProductSpec spec;
public SalesLineItem(ProductSpec spec, int quantity) {
this.spec = spec;
this.quantity = quantity;
}
public int getSubTotal() {
int price = spec.getPrice();
return price * quantity;
}
// 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음
public int getItemUpc() {
return spec.getUpc();
}
// 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음
public String getItemName() {
return spec.getName();
}
// 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음
public int getItemPrice() {
return spec.getPrice();
}
// 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음
public int getQuantity() {
return quantity;
}
}
-----------------------------------------------------------
import java.util.HashMap;
public class ProductCatalog {
private HashMap<Integer, ProductSpec> specTable = new HashMap<Integer, ProductSpec>();
public void addSpec(int upc, ProductSpec spec) {
specTable.put(upc, spec);
}
public ProductSpec spec(int upc) {
return specTable.get(upc);
}
}
-----------------------------------------------------------
public class ProductSpec {
private int upc;
private String name;
private int price;
public ProductSpec(int upc, String name, int price) {
this.upc = upc;
this.name = name;
this.price = price;
}
public int getPrice() {
return price;
}
// 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음
public int getUpc() {
return upc;
}
// 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음
public String getName() {
return name;
}
}
-----------------------------------------------------------
导入java.util.Date;
公营职位{
私人店铺;
私人产品目录;
私人销售=空;
公共邮政(商店、产品目录){
this.store=商店;
this.catalog=目录;
}
公共无效项(整数upc,整数数量){
如果(销售==null){
日期日期=新日期(System.currentTimeMillis());
销售=新销售(日期);
}
ProductSpec s=catalog.spec(upc);
sale.makeLineItem(s,数量);
}
公众付款(){
如果(sale!=null)sale.makePayment();
}
公开发售(){
store.addCompleteSale(销售);
sale=null;
}
}
-----------------------------------------------------------
导入java.util.ArrayList;
公共类商店{
受保护的ArrayList completedSales=null;
公共商店(){
completedSales=new ArrayList();
}
公开作废addCompleteSale(出售){
完成销售。添加(销售);
}
}
-----------------------------------------------------------
导入java.util.ArrayList;
导入java.util.Date;
公务舱销售{
私人日期;
私有ArrayList lineItem=null;
私人支付=空;
公开发售(日期)
{
this.date=日期;
lineItem=新的ArrayList();
}
公共void makeLineItem(产品规格s,整数数量){
SalesLineItem=新的SalesLineItem(s,数量);
行项目。添加(项目);
}
公共int getTotal(){
int-total=0;
用于(SalesLineItem项目:lineItem){
合计+=项目。getSubTotal();
}
返回总数;
}
公众付款(){
int total=this.getTotal();
付款=新付款(总计);
}
// 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음
公共日期getDate(){
返回日期;
}
// 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음
public void printLineItems(){
用于(SalesLineItem项目:lineItem){
System.out.println(“upc:+item.getItemUpc()+”,名称:“+item.getItemName()+”,价格:”
+item.getItemPrice()+”,数量:“+item.getQuantity());
}
}
}
-----------------------------------------------------------
公共类支付{
私人整数金额;
公共支付(整数金额){
这个。金额=金额;
}
// 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음
公共整数getAmount(){
退货金额;
}
}
-----------------------------------------------------------
公共类SalesLineItem{
私人整数数量;
私人产品规范;
公共SalesLineItem(ProductSpec spec,整数数量){
this.spec=spec;
这个。数量=数量;
}
公共整数getSubTotal(){
int price=spec.getPrice();
退货价格*数量;
}
// 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음
public int getItemUpc(){
返回规范getUpc();
}
// 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음
公共字符串getItemName(){
返回spec.getName();
}
// 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음
public int getItemPrice(){
返回规格getPrice();
}
// 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음
公共整数getQuantity(){
退货数量;
}
}
-----------------------------------------------------------
导入java.util.HashMap;
公共类产品目录{
private HashMap specTable=new HashMap();
公共无效添加规范(int upc、ProductSpec规范){
specTable.put(upc,spec);
}
公共产品规范(int upc){
返回specTable.get(upc);
}
}
-----------------------------------------------------------
公共类产品规范{
私立国际大学;
私有字符串名称;
私人int价格;
公共产品规范(整数upc、字符串名称、整数价格){
this.upc=upc;
this.name=名称;
这个价格=价格;
}
public int getPrice(){
退货价格;
}
// 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음
public int getUpc(){
返回upc;
}
// 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음
公共字符串getName(){
返回名称;
}
}
不要介意代码中的韩语,它们只是为了一些描述。下面的一张图片是我画的图表,不管它是否正确
主要的问题是,我不知道是否应该绘制在终止过程中使用的每个元素、交互和实例。我知道我听起来有点杂乱无章,但请有人帮我解决问题。我没有与您核对代码,看图纸是否正确。请注意,create
ProductSpec
直接返回到POST
。这可能是一个错误