|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Compiler error Please Help
Can someone please help me with this compiler error. java:28: operator * cannot be applied to int,java.lang.String
StateTaxDue = 0.03 * incomeValue - (600 * dependents); The program is: import java.io.*; import javax.swing.JOptionPane; public class StateTax { public static void main(String[] args) throws IOException { BufferedReader inData; inData = new BufferedReader(new InputStreamReader(System.in)); //declaring Variables String income, dependents; int StateTaxDue; int incomeValue = Integer.parseInt(income); int dependentsValue = Integer.parseInt(dependents); //user input System.out.println("State Tax Computation"); income = JOptionPane.showInputDialog(null, "Taxpayers Income:"); dependents = JOptionPane.showInputDialog(null, "Number Of Dependents:"); //Conversions StateTaxDue = 0.03 * incomeValue - (600 * dependents); //output JOptionPane.showMessageDialog(null, "State Tax Due:" + StateTaxDue); System.exit(0); } } |
|
#2
|
||||
|
||||
|
At first, I don't see the error. Could it be that 0.03 should be written as .03 ?
But since you're working with 2 constants, you could declare them at the beginning of you class, like this protectedfinal int PERCENTAGE = .03; This way, if your class should become quite large, you have an overview of all constants at the beginning of the class. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Compiler error Please Help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|