MissouriTiger
Programmer
I have created 3 classes, as follows:
1. An applet which will call methods of the other two.
2. StringToInt, which converts a string to int datatype.
3. CalcBestPlan, which performs decision/calculation, giving results in multiple variables.
My problems are as follows:
1. I am confused as to how to call the main methods of classes 2 and 3 (above) from class 1. You will probably be able to see my confusion by looking at my code. I am using constructors, even though I don't think that's the right way. But I cannot find any other way to do it.
2. StringToInt has a problem in the catch part. It's suposed to give an alert window if it encounters non-numeric input. I cannot seem to get it exactly right.
Could someone please show me how to call these other classes to use their Main methods, and troubleshoot. I'm posting a lot of code here. Is this apropriate? If not please let me know.
Here's my code:
*************************************
Applet's actionPerformed method which calls the other classes.
*************************************
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == btnCalc)
{
StringToInt Converter;
strDayMin = txtDayMin.getText();
intDayMin = (Converter = new StringToInt(strDayMin));
strEveMin = txtEveMin.getText();
intEveMin = StringToInt(strEveMin);
CalcBestPlan Calculator = new CalcBestPlan(intDayMin, intEveMin);
displayResults();
}
}
*********************************************************
CalcBestPlan Class. As you can see, there are many variables which I need to access from the applet. Is there anything wrong with the way I have declared this one?
*********************************************************
public class CalcBestPlan
{
String strPlan1Name = "Free Eve/Weekend";
String strPlan2Name = "Normal";
String strPlan3Name = "High volume";
String strBestPlanName = "NoName";
double dblPlan1Fee = 10.00;
double dblPlan2Fee = 0.00;
double dblPlan3Fee = 5.00;
double dblBestPlanFee;
double dblPlan1DayRate = 35;
double dblPlan2DayRate = 25;
double dblPlan3DayRate = 15;
double dblBestPlanDayRate;
double dblPlan1EveRate = 0;
double dblPlan2EveRate = 10;
double dblPlan3EveRate = 5;
double dblBestPlanEveRate;
public void main (int intDayMin, int intEveMin)
{
if (intDayMin > intEveMin)
{
if (dblPlan1DayRate < dblPlan2DayRate)
{
if (dblPlan1DayRate < dblPlan3DayRate)
strBestPlanName = strPlan1Name;
else
strBestPlanName = strPlan3Name;
}
else
{
if (dblPlan2DayRate < dblPlan3DayRate)
strBestPlanName = strPlan2Name;
else
strBestPlanName = strPlan3Name;
}
}
else if (intEveMin == intDayMin)
{
if (dblPlan1EveRate < dblPlan2EveRate)
{
if (dblPlan1EveRate < dblPlan3EveRate)
strBestPlanName = strPlan1Name;
else
strBestPlanName = strPlan3Name;
}
else
{
if (dblPlan2EveRate < dblPlan3EveRate)
strBestPlanName = strPlan2Name;
else
strBestPlanName = strPlan3Name;
}
}
else if (intEveMin > intDayMin)
{
if (dblPlan1EveRate < dblPlan2EveRate)
{
if (dblPlan1EveRate < dblPlan3EveRate)
strBestPlanName = strPlan1Name;
else
strBestPlanName = strPlan3Name;
}
else
{
if (dblPlan2EveRate < dblPlan3EveRate)
strBestPlanName = strPlan2Name;
else
strBestPlanName = strPlan3Name;
}
}
if (strBestPlanName == strPlan1Name)
{
dblBestPlanFee = dblPlan1Fee;
dblBestPlanDayRate = dblPlan1DayRate;
dblBestPlanEveRate = dblPlan1EveRate;
}
else if (strBestPlanName == strPlan2Name)
{
dblBestPlanFee = dblPlan2Fee;
dblBestPlanDayRate = dblPlan2DayRate;
dblBestPlanEveRate = dblPlan2EveRate;
}
else if (strBestPlanName == strPlan3Name)
{
dblBestPlanFee = dblPlan3Fee;
dblBestPlanDayRate = dblPlan3DayRate;
dblBestPlanEveRate = dblPlan3EveRate;
}
//strBestPlanName = "test";
//return strBestPlanName;
}
}
******************************************************
StringToInt Class. Returns an int. It won't compile.
******************************************************
public class StringToInt
{
public int main (String strString)
{
try
{
int intString = Integer.parseInt(strString.trim());
return intString;
}
catch (NumberFormatException nfe)
{
return 000;
//mainWindow.eval("alert('The requested operation can only be performed on a numeric value. Please be sure that all inputs are valid.')"
//System.out.println("NumberFormatException: " + nfe.getMessage());
}
}
}
I would be grateful for any help anyone can offer,
Greg
1. An applet which will call methods of the other two.
2. StringToInt, which converts a string to int datatype.
3. CalcBestPlan, which performs decision/calculation, giving results in multiple variables.
My problems are as follows:
1. I am confused as to how to call the main methods of classes 2 and 3 (above) from class 1. You will probably be able to see my confusion by looking at my code. I am using constructors, even though I don't think that's the right way. But I cannot find any other way to do it.
2. StringToInt has a problem in the catch part. It's suposed to give an alert window if it encounters non-numeric input. I cannot seem to get it exactly right.
Could someone please show me how to call these other classes to use their Main methods, and troubleshoot. I'm posting a lot of code here. Is this apropriate? If not please let me know.
Here's my code:
*************************************
Applet's actionPerformed method which calls the other classes.
*************************************
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == btnCalc)
{
StringToInt Converter;
strDayMin = txtDayMin.getText();
intDayMin = (Converter = new StringToInt(strDayMin));
strEveMin = txtEveMin.getText();
intEveMin = StringToInt(strEveMin);
CalcBestPlan Calculator = new CalcBestPlan(intDayMin, intEveMin);
displayResults();
}
}
*********************************************************
CalcBestPlan Class. As you can see, there are many variables which I need to access from the applet. Is there anything wrong with the way I have declared this one?
*********************************************************
public class CalcBestPlan
{
String strPlan1Name = "Free Eve/Weekend";
String strPlan2Name = "Normal";
String strPlan3Name = "High volume";
String strBestPlanName = "NoName";
double dblPlan1Fee = 10.00;
double dblPlan2Fee = 0.00;
double dblPlan3Fee = 5.00;
double dblBestPlanFee;
double dblPlan1DayRate = 35;
double dblPlan2DayRate = 25;
double dblPlan3DayRate = 15;
double dblBestPlanDayRate;
double dblPlan1EveRate = 0;
double dblPlan2EveRate = 10;
double dblPlan3EveRate = 5;
double dblBestPlanEveRate;
public void main (int intDayMin, int intEveMin)
{
if (intDayMin > intEveMin)
{
if (dblPlan1DayRate < dblPlan2DayRate)
{
if (dblPlan1DayRate < dblPlan3DayRate)
strBestPlanName = strPlan1Name;
else
strBestPlanName = strPlan3Name;
}
else
{
if (dblPlan2DayRate < dblPlan3DayRate)
strBestPlanName = strPlan2Name;
else
strBestPlanName = strPlan3Name;
}
}
else if (intEveMin == intDayMin)
{
if (dblPlan1EveRate < dblPlan2EveRate)
{
if (dblPlan1EveRate < dblPlan3EveRate)
strBestPlanName = strPlan1Name;
else
strBestPlanName = strPlan3Name;
}
else
{
if (dblPlan2EveRate < dblPlan3EveRate)
strBestPlanName = strPlan2Name;
else
strBestPlanName = strPlan3Name;
}
}
else if (intEveMin > intDayMin)
{
if (dblPlan1EveRate < dblPlan2EveRate)
{
if (dblPlan1EveRate < dblPlan3EveRate)
strBestPlanName = strPlan1Name;
else
strBestPlanName = strPlan3Name;
}
else
{
if (dblPlan2EveRate < dblPlan3EveRate)
strBestPlanName = strPlan2Name;
else
strBestPlanName = strPlan3Name;
}
}
if (strBestPlanName == strPlan1Name)
{
dblBestPlanFee = dblPlan1Fee;
dblBestPlanDayRate = dblPlan1DayRate;
dblBestPlanEveRate = dblPlan1EveRate;
}
else if (strBestPlanName == strPlan2Name)
{
dblBestPlanFee = dblPlan2Fee;
dblBestPlanDayRate = dblPlan2DayRate;
dblBestPlanEveRate = dblPlan2EveRate;
}
else if (strBestPlanName == strPlan3Name)
{
dblBestPlanFee = dblPlan3Fee;
dblBestPlanDayRate = dblPlan3DayRate;
dblBestPlanEveRate = dblPlan3EveRate;
}
//strBestPlanName = "test";
//return strBestPlanName;
}
}
******************************************************
StringToInt Class. Returns an int. It won't compile.
******************************************************
public class StringToInt
{
public int main (String strString)
{
try
{
int intString = Integer.parseInt(strString.trim());
return intString;
}
catch (NumberFormatException nfe)
{
return 000;
//mainWindow.eval("alert('The requested operation can only be performed on a numeric value. Please be sure that all inputs are valid.')"
//System.out.println("NumberFormatException: " + nfe.getMessage());
}
}
}
I would be grateful for any help anyone can offer,
Greg