gpt4 book ai didi

java - 预期 token 存在语法错误

转载 作者:行者123 更新时间:2023-12-01 08:03:56 24 4
gpt4 key购买 nike

我正在尝试解决问题

syntax error on token "}" , { expected.

该程序应该能够计算输入金额的税费。

import javax.swing.JOptionPane;
public class Accounting {

/**
* @param args
*/

public static void main(String[] args) {
// TODO Auto-generated method stub

//declare variables
int accountNumber;
int age=0;
int months=0;
double amount=0.0;
double increasedAmount=0.0;
double incomeTax=0.0;
double newAmount=0.0;
char letter;
double rate=0.03;
double interest=0.0;
double tax=0.40;
double income=0.0;


//get input
accountNumber=Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter the account number (Type 999 to exit "));
age=Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the age "));
amount=Double.parseDouble(JOptionPane.showInputDialog(null, "Enter the amount "));
months=Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the number of months "));

letter=(JOptionPane.showInputDialog(null, "--- --- Main Menu --- --- --- " +
"\n A. Seniors Account " + "\n B. Income Tax " + "\n C. Special Accounts " +
"\n Please select a letter from the menu ( Type X to exit the Menu)")).charAt(0);



//call function

interest=amount*rate*months;

income=amount*tax;

increasedAmount=calcSenior(amount, interest);

incomeTax=calcTax(amount, income );


//display results
JOptionPane.showMessageDialog(null, "The increased amount is " + increasedAmount);
JOptionPane.showMessageDialog(null, "The income tax is " + incomeTax);}



public static void displayHeading()
{
JOptionPane.showMessageDialog(null, "############################# ");
JOptionPane.showMessageDialog(null, "Als Accounting Services ");
JOptionPane.showMessageDialog(null, "Your success is our business. ");
JOptionPane.showMessageDialog(null, "############################# ");

}



// code methods

//case 1:
public static double calcSenior (double amt, double intest)
{
double cost;
cost=amt+intest;
return cost;

}

//case 2:
public static double calcTax(double amot, double inc)
{
double cost1;
cost1=amot+inc;
return cost1;

}

//case 3:
public static void makeDeductions (int age, double amount)
{
double newAmount;
if (age > 40)
{
newAmount=amount-100;
JOptionPane.showMessageDialog(null, "Amount " + amount);
}
else
{
JOptionPane.showMessageDialog(null, "No deductions at this time ");
}
}
} - error

while (accountNumber != 999)
{
Accounting.displayHeading();

switch (accountNumber)
{
case 1:
calcSenior();
break;

case 2:
calcTax();
break;

case 3:
makeDeductions();
break;
default: JOptionPane.showMessageDialog(null, "Bye! Have a nice day ");

}//end switch

}
}
}

最佳答案

问题是,你的 while 循环超出了类定义的主体......

public class Accounting {
//...
} // End of class..

while...

这在 Java 中是非法的。您必须将 while 循环放置在执行上下文中,例如方法或静态初始化程序 block ...

关于java - 预期 token 存在语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23049832/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com