如何为伪代码和类图创建正确的 if then else 语句
首先,我很抱歉没有先详细说明和澄清这个问题,所以我现在就这样做。
我目前正在尝试完成一项需要 UML 类图和伪代码的实验室练习(主题是地震)。
所需的方法之一名为确定分类(),
因此对于伪代码,需要为上述方法提供一个 if then else 语句。
示例
magnitude
0-3
4-6
classification
little
medium
determineclassification()
If magnitude 0 > and magnitude < 3
then
classification = little
elseif magnitude 4 > and magnitude < 6
then
classification = medium
,反之亦然
我想知道我使用的正确方法是否是创建 if-then-else 语句的正确方法。
First off I apologize for not elaborating and clarifying the question first, so I will do that right now.
I am currently trying to complete a a lab exercise (topic is on earthquakes) that requires UML class diagram and pseudocode.
one of the method required is named the determineclassification()
so for the pseudocode it is required that you have an if then else statement for the method above.
example
magnitude
0-3
4-6
classification
little
medium
determineclassification()
If magnitude 0 > and magnitude < 3
then
classification = little
elseif magnitude 4 > and magnitude < 6
then
classification = medium
and vice versa
I was wondering if the method that I am using right is the correct way to create a if-then-else statement.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的问题可能会更清楚,但由于它在大多数语言中看起来都很相似,所以我就同意它。
我假设 >= 100 的人也很老,所以没有理由设定上限。使用<代码>< 18 和
>如果使用
可能会起作用,但在第二个范围上使用int
类型,17>=
更安全、更清晰。地震版本:
现在您已将其更改为地震示例,但您仍然弄乱了边缘情况。 3.5适合哪里? 4? 6?
Your question could be a lot clearer, but since it'll look similar in most languages I'll just go with it.
I assume people >= 100 are also old, so no reason for an upper bound. Using
< 18
and> 17
may work if usingint
types, but it's safer and clearer just to use>=
on the second range.Earthquake version:
Now that you've change it to this earthquake example, you're still messing up your edge cases. Where does 3.5 fit? 4? 6?
你的伪代码非常好,没有任何问题。除非您想为年龄 > 的人创建另一个限定符,否则第二个
if
中不需要上限。 100,例如古老的或其他的。You have pretty good pseudo code, there is nothing wrong in it. There is no need for an upper bound in the second
if
unless you want to create another qualifier for people whoseage > 100
, e.g. ancient or something.