简体   繁体   English

为Shoe类创建UML图

[英]Creating UML diagram for Shoe class

I am taking an online class and I am having some trouble with this assignment. 我正在参加在线课程,但此作业遇到一些麻烦。

I'm having trouble with part 1 "A default constructor that initializes each attribute to some reasonable default value for non-existent shoes." 我在第1部分中遇到了麻烦:“一个默认构造函数,该构造函数将每个属性初始化为不存在的鞋子的某个合理的默认值。”

Here's what I have: 这是我所拥有的:

Shoe 鞋子


(-) style: String (-)样式:字符串

(-) color: String (-)颜色:字符串

(-) size: Integer (-)大小:整数


(+) setSyle (s: String) (+)setSyle(s:字符串)

(+) setColor (c: String) (+)setColor(c:字符串)

(+) setSize (z: Integer) (+)setSize(z:整数)

(+) getSyle () : String (+)getSyle():字符串

(+) getColor () : String (+)getColor():字符串

(+) getSize () : Integer (+)getSize():整数

Assignment: 分配:

The Showy Shiny Shoe Store sells different styles of shoes, such as sandals and walking shoes. Showy Shiny Shoe Store商店出售不同款式的鞋子,例如凉鞋和步行鞋。 Each style of shoe is offered in different colors, such as brown and black. 每种款式的鞋都有不同的颜色,例如棕色和黑色。 Available shoe sizes range from size 5 to size 11, in both whole and half sizes. 可用的鞋号从5号到11号不等,包括全码和半码。 Design an object-oriented computer program by doing the following: 通过执行以下操作来设计一个面向对象的计算机程序:

Part I 第一部分

. Create the class diagram for the Shoe class that contains the style of the shoes, the color of the shoes, and the size. 为Shoe类创建类图,其中包含鞋子的样式,鞋子的颜色和尺寸。 Examples of valid values for the style are "sandals" and "walking". 样式的有效值示例为“凉鞋”和“步行”。 Examples of valid values for the color are "brown" and "black". 颜色的有效值示例为“棕色”和“黑色”。 Examples of valid values for the size are 6.5 and 9.0. 有效的大小示例包括6.5和9.0。 Be sure to choose the most appropriate data type for the attributes. 确保为属性选择最合适的数据类型。 For this class definition, include the following: 对于此类定义,请包括以下内容:

  • A default constructor that initializes each attribute to some reasonable default value for non-existent shoes. 一个默认构造函数,用于将每个属性初始化为不存在的鞋子的某个合理的默认值。
  • Another constructor method that has a parameter for each data member. 另一个构造函数方法,每个数据成员都有一个参数。 This constructor initializes each attribute to the value provided when an object of this type is instantiated. 此构造函数将每个属性初始化为实例化此类型的对象时提供的值。
  • Accessor and mutator methods for each attribute. 每个属性的访问器和更改器方法。 Part II - 第二部分-

Write the pseudo code for the Shoe class that was designed in the class diagram in part I. Part III - 编写第一部分在类图中设计的Shoe类的伪代码。第三部分-

Write the pseudocode for the application program for the shoe store with a main() module that instantiates two objects of the Shoe class. 使用main()模块为鞋店的应用程序编写伪代码,该模块实例化Shoe类的两个对象。 The first object should be named nerdShoes and use the default constructor. 第一个对象应命名为nerdShoes并使用默认构造函数。 The second object should be named coolShoes and use the second constructor to initialize the style to "sandals", the color to "brown", and the size to 8.5. 第二个对象应命名为coolShoes,并使用第二个构造函数将样式初始化为“凉鞋”,颜色初始化为“棕色”,尺寸初始化为8.5。 Include the following instructions in the main() method, in the order specified below: A call to set the color of the nerdShoes to "tan". 按照以下指定的顺序,在main()方法中包括以下指令:调用,将nerdShoes的颜色设置为“ tan”。 A call to set the style of the nerdShoes to “walking" A call to set the size of the nerdShoes to 9.5. A statement that displays the style of the nerdShoes, using the appropriate method call. A call to change the color of the coolShoes to "purple". A statement that displays the style of the coolShoes, using the appropriate method call. 将nerdShoes的样式设置为“ walking”的调用将nerdShoes的大小设置为9.5的调用,使用适当的方法调用显示nerdShoes的样式的声明。使用适当的方法调用来显示coolShoes样式的语句。

Normally I don't answer with entire code, as this is something you need to work on. 通常我不会回答完整的代码,因为这是您需要进行的工作。 You learn more and better when you try by yourself. 当您自己尝试时,您会学到更多更好的东西。

But I will send my suggestion as I like UML questions... (though this was simple UML in it). 但是,当我喜欢UML问题时,我会发送我的建议...(尽管其中是简单的UML)。

But I m wondering why using size as Integer? 但是我想知道为什么使用size作为Integer? You mention you need half sizes ? 您提到需要一半尺寸吗? My suggestion would be using eg float . 我的建议是使用float

鞋UML

package theshowyshinyshoestore;

public class Shoe {
  String style;
  float size;
  String color;

  public Shoe() {
      setStyle("unknown");
      setSize(0);
      setColor("unknown");
  }

  public Shoe(String style, float size, String color) {
      setStyle(style);
      setSize(size);
      setColor(color);
  }

  public void setStyle( String style ) {
      //perform checks for valid style
      //...
      this.style = style;
  }

  public void setSize( float size ) {
      //perform checks for valid size
      //...
      this.size = size;
  }

  public void setColor( String color ) {
      //perform checks for valid colors
      //...
      this.color = color;
  }

  public String getStyle() {
    return this.style;
  }

  public float getSize() {
    return this.size;
  }

  public String getColor() {
    return this.color;
  }


  public String toString() {
    return "Style: " + this.style + " Size: " + this.size + " Color: " + this.color;
  }


  public static void main(String[] argv) {
    Shoe nerdShoes = new Shoe();
    Shoe coolShoes = new Shoe("sandals", 8.5f, "brown");
    System.out.println( "nerdShoes: " + nerdShoes );
    System.out.println( "coolShoes: " + coolShoes );

    nerdShoes.setColor("tan");
    nerdShoes.setStyle("walking");
    nerdShoes.setSize(9.5f);

    coolShoes.setColor("purple");

    System.out.println( "nerdShoes: " + nerdShoes );

    System.out.println( "nerdShoes style: " + nerdShoes.getStyle() );
    System.out.println( "coolShoes style: " + coolShoes.getStyle() );
  }

}

A default constructor is identified by not accepting any parameters. 通过不接受任何参数来标识默认构造函数。 My guess about the default values is that they are some placeholder values for your variables. 我对默认值的猜测是它们是您的变量的一些占位符值。 A possible solution might look like this: 可能的解决方案如下所示:

public Shoe(){ this.style = ""; this.color = ""; this.size = 0; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM