File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes help convert java code to pseudo code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help convert java code to pseudo code" Watch "help convert java code to pseudo code" New topic
Author

help convert java code to pseudo code

jacelyn chia
Greenhorn

Joined: Jul 24, 2008
Posts: 1
any kind soul can help me convert Java code to pseudo code??? My due is 20hrs later !!! please help

package assignment;

import javax.swing.JOptionPane;
import javax.*;
public class Array
{
public static void main (String args[])
{
int inputInt = 0;
String errorMsg;
String wanaPlayInput;

do{ //set the flag for input as true at first
boolean inputAgain = true;

while (inputAgain){
String tryInput = JOptionPane.showInputDialog("How many numbers do you want to enter");
try{
errorMsg = "";
inputInt = Integer.parseInt(tryInput);//try to change string into integer type
}
catch(Exception e){
errorMsg = e.getMessage();//input is not a number
//System.out.println("Exception!!" + errorMsg);
}
if(errorMsg.equals(""))//if no error msg, input is a number
inputAgain = false;//need not re-input
}

Double arrayInt [] = new Double [inputInt];

String numInputStr;
double numInput;
int pos;

for(int i=0; i<inputInt; i++){
pos = i + 1;
numInputStr = JOptionPane.showInputDialog("Enter number " + pos + " between 1 and 100");
numInput = Double.parseDouble(numInputStr);
while (numInput < 1 || numInput > 100){
//System.out.println("Number is less than 1 or more than 100");
numInputStr = JOptionPane.showInputDialog("Enter number " + pos + " between 1 and 100");
numInput = Double.parseDouble(numInputStr);
}
if(numInput > 0 && numInput < 101)
arrayInt[i] = numInput;
}

for(int j=0; j<inputInt; j++){
double number = arrayInt[j];

double squaredNum = calSquare(number);
//double squaredNum = Math.pow(number,2);
//System.out.println(number + " squared is : " + squaredNum);

double cubedNum = calCube(number);
//double cubedNum = Math.pow(number,3);
//System.out.println(number + " cubed is : " + cubedNum);

String msgBox = number + " squared is " + squaredNum + "\n" +
number + " cubed is " + cubedNum;

JOptionPane.showMessageDialog (null, msgBox);
}
//System.out.println("I am outside the loop");
wanaPlayInput = JOptionPane.showInputDialog("Do you want to continue (y/n)?");
}
while (wanaPlayInput.equalsIgnoreCase("y"));
}

public static double calSquare(double number){
double squaredNum = Math.pow(number,2);
//System.out.println("Using calSquare : " + number + " squared is : " + squaredNum);
return squaredNum;
}

public static double calCube(double number){
double cubedNum = Math.pow(number,3);
//System.out.println("Using calCube : " + number + " cubed is : " + cubedNum);
return cubedNum;
}

}
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11499
    
  16

we don't do homework here for you. you should read this specifically, as well as most of the other topics here.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Welcome to JavaRanch.

Please find the code button below the "message" window when quoting code; it makes it easier to read.

It is usually easy to convert pseudo-code to code, so you should have no difficulty converting this sort of thing to Java:Now, with the similarity between pseudo-code and real code, it shouldn't be difficult to convert it back. Remember you don't have pseudo-code for a class, but for an algorithm, so it would be one block per method. I googled and found this and this, which looks better.
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
http://faq.javaranch.com/java/DoYourOwnHomework


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2718
    
    6

Although I not helping to do your homework, pseudo code represents an algorithm and the code you posted isn't really a complex one to find out.


SCJP, SCWCD.
|Asking Good Questions|
Frances Hollis
Greenhorn

Joined: Sep 02, 2006
Posts: 17
Crossposted in the Sun Forums. Twice.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help convert java code to pseudo code