aspose file tools*
The moose likes Beginning Java and the fly likes Java to PseudoCode Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java to PseudoCode" Watch "Java to PseudoCode" New topic
Author

Java to PseudoCode

Jay Smiths
Greenhorn

Joined: Apr 17, 2012
Posts: 2
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")




Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

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


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Jay Smiths
Greenhorn

Joined: Apr 17, 2012
Posts: 2
Maneesh Godbole wrote:Welcome to the Ranch.
In future, while posting code please UseCodeTags (and not quote tag)


Okay sorry, thanks for editing.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39861
    
  28
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
    Sheriff

    Joined: Oct 13, 2005
    Posts: 39861
        
      28
    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
    Sheriff

    Joined: Oct 13, 2005
    Posts: 39861
        
      28
    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.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Java to PseudoCode