Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-19-2005, 03:47 AM   PM User | #1
aa8514
New to the CF scene

 
Join Date: Oct 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
aa8514 is an unknown quantity at this point
new and clueless

i am new to javascript - it says it cannot find symbol constructor BMIndexCalculator (int, double, double) for my application.

i am trying to make an instance of my BMIndexCalculator class and call the start method in my BMIndexCalculatorMain class. below is the code, maybe someone can help? BMIndex and BMIndexCalculator compile cleanly, just the problem with BMIndexCalculatorMain. Thank you so much for any help, I am really confused. I'm trying to make a body mass index calculator. i really have no idea what to do now.


/** ---------------------------------------------------------------------
* Class : BMIndexCalculatorMain

* Description: Makes an instance of the BMIndexCalculator class and contains a start method.

*/
import javax.swing.*;
import java.util.*;
import java.text.*;

/**define main class & method*/
class BMIndexCalculatorMain {

//Main method
public static void main (String [] args) {

int age;
double weight, height;
double recWeight;

/**Use DecimalFormat to change number of decimal places displayed*/
DecimalFormat df = new DecimalFormat("0");

BMIndexCalculator calc = new BMIndexCalculator (age, weight, height);

/**Display input values and computed results using JOptionPane*/
//Displays the results

//Convert height in inches to centimeters
recWeight = ((height*2.54) - 100) + age%10 * 0.90;

JOptionPane.showMessageDialog (null, "The recommended weight for your height and age is: " + df.format(recWeight*2.2) + " lbs");
}}


/** ---------------------------------------------------------------------
* Class : BMIndexCalculator

*
* Description: Does I/O, uses an instance of the BMIndex class, contains a start method.

*
*/
import javax.swing.*;
import java.util.*;
import java.text.*;

/**define main class & method*/
class BMIndexCalculator {

//Main method
public static void main(String [] args) {

/**Get the four input values*/
//Get the four input values
int age;
double weight, height, bMI;
String inputStr;

inputStr = JOptionPane.showInputDialog (null, "Enter your Age: ");
age = Integer.parseInt(inputStr);

inputStr = JOptionPane.showInputDialog (null, "Enter Height (cm): ");
height = Double.parseDouble(inputStr);

inputStr = JOptionPane.showInputDialog (null, "Enter Weight (lbs): ");
weight = Double.parseDouble(inputStr);

/**Use DecimalFormat to change number of decimal places displayed*/
DecimalFormat df = new DecimalFormat("0.00");

//convert weight in lbs to weight in kilograms
weight = weight * 2.2;

//convert height in cm to height in meters
height = (height/100);

BMIndex calc = new BMIndex (age, weight, height);

/**Display input values and computed results using PrintStream*/
//Displays the input values and results

bMI= weight/Math.pow(height, 2);

System.out.println ("Weight: " + df.format(calc.getWeight()) + " kilograms.");
System.out.println ("Height: " + df.format(calc.getHeight()) + " meters");
System.out.println ("BMI: " + bMI * 100);
}
}



/** ---------------------------------------------------------------------
* Class : BMIndex

*
* Description: Generic BMIndex class that calculates the Body Mass Index and has no I/O.

*/
import javax.swing.*;
import java.text.*;

class BMIndex {

//Data members /**Data members*/
private int age;
private double weight;
private double height;

//Constructor /**Constructor*/
public BMIndex (int inputage, double inputweight, double inputheight) {
setAge (inputage);
setWeight(inputweight);
setHeight(inputheight);
}

//Set age
/**@param sets age, weight, height*/
public void setAge (int inputage) {
age = inputage;
}

//Set weight
public void setWeight(double inputweight) {
weight = inputweight;
}

//Set height
public void setHeight (double inputheight) {
height = inputheight;
}

/**@return returns age, weight, height*/

//Return age
public int getAge () {
return age;
}

//Return weight
public double getWeight () {
return weight;
}

//Returns height
public double getHeight () {
return height;
}
}
aa8514 is offline   Reply With Quote
Old 10-19-2005, 05:03 AM   PM User | #2
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
This is the javaSCRIPT forum not the Java forum. Ask a moderator to move this thread for you. Java and javascript are not the same language.
_Aerospace_Eng_ is offline   Reply With Quote
Old 10-19-2005, 04:04 PM   PM User | #3
nikkiH
Senior Coder

 
nikkiH's Avatar
 
Join Date: Jun 2005
Location: Near Chicago, IL, USA
Posts: 1,973
Thanks: 1
Thanked 32 Times in 31 Posts
nikkiH is on a distinguished road
BMIndexCalculator is a static thing that runs. Has only main. It has no constructor.

Your class that has a constructor that fits is BMIndex. Perhaps you meant to use that instead?
__________________

If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit
http://www.kaelisspace.com/
nikkiH is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:20 PM.


Advertisement
Log in to turn off these ads.