calling methods in a string

calling methods in a string

Post by Kelly » Fri, 26 Nov 2004 04:35:54


This is a program that computes clothing sizes by age, weight, and
height. However I am unable to get the program to display the results. I
fear I may have the code arranged wrongly or I might be missing a
declaration, but I believe the main problem is calling the methods to the
output string. Any advice would be greatly appreciated. Thanks.

//Project2.java: copute clothing sizes according to formulas, kelly
huff, csci 1236, 11-18-04
import javax.swing.JOptionPane;

public class Project2 {

/** Main method */

public static void main(String[] args) {
int i;


while (i != 0) {
//Prompt user to enter age
String ageString = JOptionPane.showInputDialog(null, "Enter Age:",
"Project 3", JOptionPane.QUESTION_MESSAGE);

//Convert age to integer
int age = Integer.parseInt(ageString);

//Prompt user to enter weight
String weightString = JOptionPane.showInputDialog(null, "Enter
Weight:", "Project 3", JOptionPane.QUESTION_MESSAGE);

//Convert weight to integer
int weight = Integer.parseInt(weightString);

//Prompt user to enter height
String heightString = JOptionPane.showInputDialog(null, "Enter
Height:", "Project 3", JOptionPane.QUESTION_MESSAGE);

//Convert height to integer
int height = Integer.parseInt(heightString);

}

//Show results
//JOptionPane.showMessageDialog(null, "The hat size is " + hood(hat) +
". \nThe jacket size is " + coat(jacket) + ".\nThe waist size is " + belt
(waist) + ".", "Project3", JOptionPane.INFORMATION_MESSAGE);
//JOptionPane.showMessageDialog(null, "The hat siz is " + hood(hat),
JOptionPane.INFORMATION_MESSAGE);
//JOptionPane.showMessageDialog(null, "The hat size is " ,
JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, reportResults(result),
JOptionPane.INFORMATION_MESSAGE);

//Ask user if they would like to repeat calculations
String repeatString = JOptionPane.showInputDialog(null, "If you would
like to repeat the calculations enter 1, otherwise enter 0:", "Project
3", JOptionPane.QUESTION_MESSAGE);

//Convert repeat string to integer
i = Integer.parseInt(repeatString);

System.exit(0);

}

//Calculate hat size

public static double hood(int weight, int height) {
double hat = (weight / height) * 2.9;
return hat;
}

//Calculate jacket size

public static double coat(int age, int weight, int height) {
double jacket;
if (age >= 40)
jacket = (((age / 40) * 1.8) + ((height * weight) / 228));
else
jacket = ((height * weight) / 228);
return jacket;

}

//Calculate waist size
public static double belt(int age, int weight, int height) {
double waist;
if (age > 28)
waist = (((age / 29) * (1 / 10)) + (weight / 5.7));
else
waist = (weight / 5.7);
return waist;

}
public static int reportResults(double hat, double jacket, double waist)
{
String resultString = "The hat size is " + hat + ". \nThe jacket size is
" + jacket + ". \nThe waist size is " + waist + ".";
JOptionPane.showMessageDialog(null, resultString, "Project 3",
JOptionPane.INFORMATION_MESSAGE);

}
}
 
 
 

calling methods in a string

Post by Boudewijn » Fri, 26 Nov 2004 06:23:19

"Kellyh" < XXXX@XXXXX.COM > schreef in bericht



Check your logic. Variable i doesn't change inside the loop.


Not neccesary unless you started additional non-daemon threads.

 
 
 

calling methods in a string

Post by Mike » Fri, 26 Nov 2004 07:53:44


Kelly, let's try one more time. Look at my previous post to you.

You have a method "hat"


It needs two (2) arguments since it has two parameters. Both must be of
class integer.

When you call this method:


You use only one (1) parameter. Frankly, I doubt your code will compile
correctly, never mind even run correctly.

The correct invocation of method "hat" would be:

//JOptionPane.showMessageDialog(null, "The hat size is " + hood(weight,
hight) +


By the way, you should be careful about exposing your identity on the
internet. Not only will you attract spam, other (bad) things may also happen
to you. From your posts I can find your name, a course and your university.
You may want to be more careful about personal information.

--
Mike B