• 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

help convert java code to pseudo code

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
}

}
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79508
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://faq.javaranch.com/java/DoYourOwnHomework
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Crossposted in the Sun Forums. Twice.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.util.ArrayList;

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic