Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help convert java code to pseudo code

 
jacelyn chia
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we don't do homework here for you. you should read this specifically, as well as most of the other topics here.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50225
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://faq.javaranch.com/java/DoYourOwnHomework
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Frances Hollis
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Crossposted in the Sun Forums. Twice.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic