calling methods in a string
From: Kellyh (khuff3_at_georgiasouthern.edu)
Date: 11/24/04
- Next message: Eduardo Bernal: "Re: NEWBIE HELP: Missing identifier?"
- Previous message: Oscar kind: "Re: Using arrays & methods"
- Next in thread: Boudewijn Dijkstra: "Re: calling methods in a string"
- Reply: Boudewijn Dijkstra: "Re: calling methods in a string"
- Reply: Mike B: "Re: calling methods in a string"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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);
}
}
- Next message: Eduardo Bernal: "Re: NEWBIE HELP: Missing identifier?"
- Previous message: Oscar kind: "Re: Using arrays & methods"
- Next in thread: Boudewijn Dijkstra: "Re: calling methods in a string"
- Reply: Boudewijn Dijkstra: "Re: calling methods in a string"
- Reply: Mike B: "Re: calling methods in a string"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|