6 Replies - 1144 Views - Last Post: 16 May 2012 - 05:49 AM Rate Topic: -----

#1 lonewolf1994  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-May 12

Is my pseudo-code correct?

Posted 16 May 2012 - 04:44 AM

Hello.

I'm learning Java so I'm pretty new to this. I'm trying to learn about Pseudo-code and I think so far I've been doing ok, however I am not so sure on one can anyone check if it is correct for me please? And if it is not, could you explain why?
Thanks


IF waterTemperature greater than or equal to 69 THEN
isStriperMostActive := false //stripers are less active
ELSEIF waterTemperature less than 69 but greater than 47 THEN
isStriperMostactive := true// Stripers are most active
ELSEIF waterTemperature less than or uqual to 47 THEN
isStriperMostActive := false// Stripers are less than active
ENDIF

	public class waterTemperature; {
if (waterTemperature >= 69);
System.out.println( "Stripers are less active");
elseif (waterTemperature < 69 && > 47);
System.out.println ("Stripers are most active");
elseif (waterTemperature <= 47);
System.out.println("Stripers are less active");

}



Thank you for any help.

Is This A Good Question/Topic? 0
  • +

Replies To: Is my pseudo-code correct?

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2197
  • View blog
  • Posts: 5,224
  • Joined: 10-September 10

Re: Is my pseudo-code correct?

Posted 16 May 2012 - 05:03 AM

I don't know that there's a right or wrong here, but I have some suggestions:

The "less active" conditions could be combined into a single if statement:
if ( waterTemp >= 69 && waterTemp <= 47 )
{
   System.out.println( "Stripers are less active.");
}

Also note that the two if conditions must be complete. They can't be shortened to what you have in line 4 of our second version.

Try to avoid practicing bad habits in whatever code style you're using. For example (the if conditions noted above, plus):

The comments in the first version are largely unnecessary, but maybe those aren't comments. Maybe you meant the "//" to indicate something that should be printed. As I've noted below, try not to use shorthand that can confuse. Then again, if the pseudocode is for you only, use whatever you want.

In both versions, you use non-Java keywords and capitalization. That may be fine in pseudocode, but why paractice doing it the wrong way, using non-standards and improper practices?

In the second version (the one in code tags), you've ended every line with a semi-colon, and that's not appropriate.
Was This Post Helpful? 0
  • +
  • -

#3 lonewolf1994  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-May 12

Re: Is my pseudo-code correct?

Posted 16 May 2012 - 05:12 AM

Thank you very much for your help.

Though, I'd like to point out that I did not make the pseudo code, it was in the study guide
and it said I had to make it into java code.
Was This Post Helpful? 0
  • +
  • -

#4 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2197
  • View blog
  • Posts: 5,224
  • Joined: 10-September 10

Re: Is my pseudo-code correct?

Posted 16 May 2012 - 05:22 AM

Okay, it would have been helpful if you'd have explained that. So the first is pseudocode from a book, and the second, in code tags, is supposed to be Java?

If the second version is supposed to be Java:

Line 1, Class names should be capitalized and do not end with a semi-colon. As a general rule, clauses that are included in braces '{}' are not preceded by a semi-colon.

Line 2, Do not end with a semi-colon. The statement following is meant to be part of the if statement, but the semi-colon ends the if statement.

Lines 4 and 6, else if instead of elseif, and do not end with a semi-colon for the same reason as above.

Line 4, fix the if conditions separated by the && as I noted in my first post.
Was This Post Helpful? 1
  • +
  • -

#5 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,416
  • Joined: 29-May 08

Re: Is my pseudo-code correct?

Posted 16 May 2012 - 05:43 AM

Erm,
if ( waterTemp >= 69 && waterTemp <= 47 )



that's a problem waterTemp can't be both greater or equal to 69 AND less or equal to 47.
Maybe it should be an OR
Was This Post Helpful? 1
  • +
  • -

#6 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2197
  • View blog
  • Posts: 5,224
  • Joined: 10-September 10

Re: Is my pseudo-code correct?

Posted 16 May 2012 - 05:46 AM

Of course it should be OR, ||. Good catch.
Was This Post Helpful? 0
  • +
  • -

#7 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,416
  • Joined: 29-May 08

Re: Is my pseudo-code correct?

Posted 16 May 2012 - 05:49 AM

If rewrite the conditional into a more mathematical style, you can combine two of the outputs.
if (47 < waterTemp && waterTemp < 69) /* A Bounds check. */
  {
  System.out.println("Stripers are most active");
  }
else
  {
  System.out.println("Stripers are less active");
  }


This post has been edited by AdamSpeight2008: 16 May 2012 - 05:52 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1