• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java to PseudoCode

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically I am a computing A-Level student in the UK

I have already written my project and had it marked however I am now really struggling in converting it to pseudo code, I have started to do it and was just wondering am I going along the right lines? Sample posted below. (Original code followed by my so called "Pseudocode")




 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.
In future, while posting code please UseCodeTags (and not quote tag)
 
Jay Smiths
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maneesh Godbole wrote:Welcome to the Ranch.
In future, while posting code please UseCodeTags (and not quote tag)



Okay sorry, thanks for editing.
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does your exam require you to write pseudo-code at all? You don’t usually convert code to pseudo-code; you usually do it the other way round, so you might be doing something unnecessary.
Pseudo-code doesn’t have a fixed syntax or format, but you usually indent things which would be in a block and
You should give each method its own block of pseudo-code, without { ot anything. You can delineate blocks by unindenting and writing something like end. so the pseudo-code to print the contents of an array would look something like this:-If that is a method you would add a heading like “Print all elements in array method”.

That’s good code, but I can see several possible improvements:
  • Look carefully at the method which searches for a customer. That will unnecessarily iterate the entire array, even if the customer is found at the first position. If there are duplicates, it will find the last entry.
  • If you know how to use a List<Customer> rather than the array, that would be more efficient use of memory, rather than occupying 100000 locations, 99995 of them empty.
  • You ought to close your writers in a finally block, like here.
  • Learn about for-each loops (enhanced for loop) for iterating an array or List.
  • The id field ought to have private access and you should be comparing equality with an overridden equals method in the Customer class. That would require overriding the hashCode method too.
  • And welcome again
     
    Campbell Ritchie
    Marshal
    Posts: 79180
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Another improvement: rather than catching Exception, catch what is actually thrown. You may require different reponses for IOException and FileNotFoundException, which are the likely exceptions from your code.
     
    Campbell Ritchie
    Marshal
    Posts: 79180
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    If you are using Java7, there is a thing called try-with-resources which gets you out of having to close the writer at all. It was not available in Java6, however.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic