开发者

how to create a proper if then else statement for pseudocode and class diagram [closed]

开发者_Go百科 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.

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.


Your question could be a lot clearer, but since it'll look similar in most languages I'll just go with it.

if (age > 10 && age < 18) {
    person = young;
}
else if (age >= 18) {
    person = old;
}

I assume people >= 100 are also old, so no reason for an upper bound. Using < 18 and > 17 may work if using int 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?

determineClassification(magnitude) {
    if (magnitude < 4)
        return "little"

    if (magnitude < 6)
        return "medium"

    return "large"
}


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 whose age > 100, e.g. ancient or something.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜