0

I have to convert this Java code to pseudocode. The program accepts 2 times and returns the time span in minutes.

In Java we have int hr1_int and int hr2_int so what they will be in pseudo code? And the String , sub-string, parseInt, try-catch structure also what will they be in pseudo?

try
{
    hr1_int = Integer.parseInt(hr1);
    min1_int = Integer.parseInt(min1);

}
catch(NumberFormatException e)
{
    System.out.println("The input time is wrong. Please reinput");
    continue;
}

hr1 = time1.substring(0,2);
Prune
  • 76,765
  • 14
  • 60
  • 81
Tran Minh Quang
  • 1
  • 1
  • 1
  • 2
  • pseudo code is not a programming language. It is a general code where works for all languages. It seems some one write pseudo code for your logic :) – Suresh Atta Oct 13 '15 at 17:25

3 Answers3

2

The pseudocode is not a specific language. It is rather pattern of design of some part of code avoiding its syntax when you

  • Don't know the language
  • Have a better things to do than care about syntax

The example can be - if you want to tell someone how to make a method to check how many array elements are odd you can write

 for every element in the array:
      if is odd:
          increase odd_counter
      else
          do nothing

 print odd_counter

it is not any language it is just "how to write it less or more"


Just to make it more visible - please look at tcooc's comment below - the valid code in Java/C++/etc can also be kind of pseudocode

m.antkowicz
  • 13,268
  • 18
  • 37
  • 3
    To add onto this answer, even your valid Java code, by definition, can be considered pseudocode. Therefore no change is necessary. – tcooc Oct 13 '15 at 17:26
1

Pseudocode varies from person to person, since it's basically just sentences/phrases formatted to look like code.

For example, I would write your example in pseudo code this way:

hour = parseInteger(hourString);
minute = parseInteger(minuteString);
if (errors)
    output("error message");

That's just me though, I prefer my pseudocode to look more code-like. Someone else might write the exact same example like so:

Try to
    Parse hour integer,
    Parse minute integer
If there were errors,
    Write the errors to console.

It's totally dependent on the person writing it.

Mage Xy
  • 1,803
  • 30
  • 36
  • if in the java program i have initialized a lot of things ( e.g int a , double b) apart from the user input. Do i also need to put it in pseudo code ? if yes what should it be – Tran Minh Quang Oct 14 '15 at 04:26
  • and if i make something in java like if ( ' a ' == ' b ' ) { break; ( mean continue to next loop else it will repeat asking a question) } then what should it be in pseudo code ? Thanks a lot for your help – Tran Minh Quang Oct 14 '15 at 04:30
  • @TranMinhQuang What do you think it should be? Chance are you're probably right in whatever you choose. Like I state in my answer, the point of pseudocode is to describe an algorithm. *There is no right or wrong answer* as long you're accurately describing what the code is doing. – Mage Xy Oct 14 '15 at 13:26
0
public String getPlatform ()
{
   return this.Platform;
}

public String getInterviewerName ()
{
   return this.InterviewerName;
}

public String getDeveloperName ()
{
   return this.DeveloperName;
}

public int getWorkingHour ()
{
   return this.WorkingHour;
}

public void setDeveloperName (String newDeveloperName)
{
   this.DeveloperName = newDeveloperName;
}

public void Display ()
{
   System.out.println ("The platform is :" + this.Platform);
   System.out.println ("The interviewer name is:" + this.InterviewerName);
   System.out.println ("The Working Hour is:" + this.WorkingHour);

   if (this.DeveloperName != "")
   {
      System.out.println ("The developer's name is:" + this.DeveloperName);
   }
}
iikkoo
  • 2,810
  • 6
  • 33
  • 38