calling methods in a string

From: Kellyh (khuff3_at_georgiasouthern.edu)
Date: 11/24/04


Date: Wed, 24 Nov 2004 19:35:54 +0000

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);

 }
 }



Relevant Pages

  • Help calling methods!
    ... String ageString = JOptionPane.showInputDialog(null, "Enter Age:", ... int age = Integer.parseInt; ... String weightString = JOptionPane.showInputDialog(null, "Enter Weight:", ...
    (comp.lang.java.help)
  • help
    ... String ageString = JOptionPane.showInputDialog(null, "Enter Age:", "Project ... int age = Integer.parseInt; ... String weightString = JOptionPane.showInputDialog(null, "Enter Weight:", ...
    (comp.lang.java.help)
  • Re: Image for composite types
    ... String a la 'Image for scalar types. ... Age: Natural; ... Weight: Float; ... Person'Number_Of_Components loop ...
    (comp.lang.ada)
  • Re: Searching OO Associations with RDBMS Persistence Models
    ... An object definition is a collection of properties. ... type Person {name: string, age: int} ...
    (comp.object)
  • Re: * struct-like list *
    ... int Birhtday; ... john.name = "John Brown" ... self.age = age ... here you could read all as string and split it on "New" ...
    (comp.lang.python)