我目前正在编写一个程序,其中我有一串方法设置基本相同。如果给他们 i = 1,他们将返回产品价格乘以订购数量。否则,他们只会退回订购的数量。但是,每当我尝试编译它时,编译器都会说括号缺少返回语句。我已经多次浏览了代码,我没有看到语法中有任何明显的错误。关于为什么会发生这种情况的任何猜测?
感谢您的任何帮助。
相关来源:
private class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == switchCard)
{
cl.show(infoPanel, (String)candyList.getSelectedValue());
}
if (e.getSource() == checkoutButton)
{
double acidPops = acidPopsTotal(1);
double bertieBotts = bertieBottsTotal(1);
double bloodPops = bloodPopsTotal(1);
double cauldronCakes = cauldronCakesTotal(1);
double charmChoc = charmChocTotal(1);
double chocoballs = chocoballsTotal(1);
double chocCauldrons = chocCauldronsTotal(1);
double chocFrogs = chocFrogsTotal(1);
double chocWands = chocWandsTotal(1);
double roachClusters = roachClustersTotal(1);
double crystalPineapple = crystalPineappleTotal(1);
double droobleGum = droobleGumTotal(1);
double explodeBonbons = explodeBonbonsTotal(1);
double fizzWhiz = fizzWhizTotal(1);
double iceMice = iceMiceTotal(1);
double jellySlugs = jellySlugsTotal(1);
double liquorWands = liquorWandsTotal(1);
double pepImpts = pepImpsTotal(1);
double pinkIce = pinkIceTotal(1);
double shockChoc = shockChocTotal(1);
double spindleSpiders = spindleSpidersTotal(1);
double quills = quillsTotal(1);
double wizochoc = wizochocTotal(1);
}
}
double acidPopsTotal(int i)
{
if (i == 1)
{
try
{
return (5.95* (Integer.parseInt(acidPopsTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(acidPopsTF.getText());
}
catch (NumberFormatException e) {}
}
}
double bertieBottsTotal(int i)
{
if (i == 1)
{
try
{
return (16.95 * (Integer.parseInt(bertieBottsTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(bertieBottsTF.getText());
}
catch (NumberFormatException e) {}
}
}
double bloodPopsTotal(int i)
{
if (i == 1)
{
try
{
return (5.95 * (Integer.parseInt(bloodPopsTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(bloodPopsTF.getText());
}
catch (NumberFormatException e) {}
}
}
double cauldronCakesTotal(int i)
{
if (i == 1)
{
try
{
return (14.95 * (Integer.parseInt(cauldronCakesTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(cauldronCakesTF.getText());
}
catch (NumberFormatException e) {}
}
}
double charmChocTotal(int i)
{
if (i == 1)
{
try
{
return (5.95 * (Integer.parseInt(charmChocTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(charmChocTF.getText());
}
catch (NumberFormatException e) {}
}
}
double chocoballsTotal(int i)
{
if (i == 1)
{
try
{
return (9.95 * (Integer.parseInt(chocoballsTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(chocoballsTF.getText());
}
catch (NumberFormatException e) {}
}
}
double chocCauldronsTotal(int i)
{
if (i == 1)
{
try
{
return (14.95 * (Integer.parseInt(chocCauldronsTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(chocCauldronsTF.getText());
}
catch (NumberFormatException e) {}
}
}
double chocFrogsTotal(int i)
{
if (i == 1)
{
try
{
return (14.95 * (Integer.parseInt(chocFrogsTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(chocFrogsTF.getText());
}
catch (NumberFormatException e) {}
}
}
double chocWandsTotal(int i)
{
if (i == 1)
{
try
{
return (9.95 * (Integer.parseInt(chocWandsTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(chocWandsTF.getText());
}
catch (NumberFormatException e) {}
}
}
double roachClustersTotal(int i)
{
if (i == 1)
{
try
{
return (5.95 * (Integer.parseInt(roachClustersTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(roachClustersTF.getText());
}
catch (NumberFormatException e) {}
}
}
double crystalPineappleTotal(int i)
{
if (i == 1)
{
try
{
return (9.95 * (Integer.parseInt(crystalPineappleTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(crystalPineappleTF.getText());
}
catch (NumberFormatException e) {}
}
}
double droobleGumTotal(int i)
{
if (i == 1)
{
try
{
return (2.95 * (Integer.parseInt(droobleGumTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(droobleGumTF.getText());
}
catch (NumberFormatException e) {}
}
}
double explodeBonbonsTotal(int i)
{
if (i == 1)
{
try
{
return (9.95 * (Integer.parseInt(explodeBonbonsTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(explodeBonbonsTF.getText());
}
catch (NumberFormatException e) {}
}
}
double fizzWhizTotal(int i)
{
if (i == 1)
{
try
{
return (9.95 * (Integer.parseInt(fizzWhizTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(fizzWhizTF.getText());
}
catch (NumberFormatException e) {}
}
}
double iceMiceTotal(int i)
{
if (i == 1)
{
try
{
return (5.95 * (Integer.parseInt(iceMiceTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(iceMiceTF.getText());
}
catch (NumberFormatException e) {}
}
}
double jellySlugsTotal(int i)
{
if (i == 1)
{
try
{
return (2.95 * (Integer.parseInt(jellySlugsTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(jellySlugsTF.getText());
}
catch (NumberFormatException e) {}
}
}
double liquorWandsTotal(int i)
{
if (i == 1)
{
try
{
return (9.95 * (Integer.parseInt(liquorWandsTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(liquorWandsTF.getText());
}
catch (NumberFormatException e) {}
}
}
double pepImpsTotal(int i)
{
if (i == 1)
{
try
{
return (4.95 * (Integer.parseInt(pepImpsTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(pepImpsTF.getText());
}
catch (NumberFormatException e) {}
}
}
double pinkIceTotal(int i)
{
if (i == 1)
{
try
{
return (4.95 * (Integer.parseInt(pinkCocoIceTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(pinkCocoIceTF.getText());
}
catch (NumberFormatException e) {}
}
}
double shockChocTotal(int i)
{
if (i == 1)
{
try
{
return (4.95 * (Integer.parseInt(shockChocTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(shockChocTF.getText());
}
catch (NumberFormatException e) {}
}
}
double spindleSpidersTotal(int i)
{
if (i == 1)
{
try
{
return (4.95 * (Integer.parseInt(spindleSpidersTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(spindleSpidersTF.getText());
}
catch (NumberFormatException e) {}
}
}
double quillsTotal(int i)
{
if (i == 1)
{
try
{
return (1.95 * (Integer.parseInt(sugarQuillsTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(sugarQuillsTF.getText());
}
catch (NumberFormatException e) {}
}
}
double wizochocTotal(int i)
{
if (i == 1)
{
try
{
return (5.95 * (Integer.parseInt(wizochocTF.getText())));
}
catch (NumberFormatException e) {}
}
else
{
try
{
return Integer.parseInt(wizochocTF.getText());
}
catch (NumberFormatException e) {}
}
}
}
错误:
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:490: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:510: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:530: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:550: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:570: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:590: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:610: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:630: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:650: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:670: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:690: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:710: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:730: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:750: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:770: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:790: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:810: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:830: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:850: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:870: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:890: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:910: error: missing return statement
}
^
C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java:930: error: missing return statement
}
^
Note: C:\Users\Sam\Desktop\Java\4H 2012\ClientApp.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
23 errors