Can anyone tell me why this won't compile. Error " reached end of file while parsing" which probably means that the brackets are not paired. I got to the point where I was sticking brackets everywhere just to see if it would work. Need help. I have attached the java file.
/*Chapter 7, Case Project "The Tax Advantage Company", Page 263.
This is an application that prompts a user for inputs to create a Taxreturn object.
Filename is PrepareTax.java
Written by Mark DeMuynck
Wednesday, July 7, 2009
Java Version 6 Update 13 (build 1.6.0_13-b03)*/
while (errstatus == 1)
{
sinString = JOptionPane.showInputDialog(null,
"Enter your Social Insurance Number with format 999-999-999.");
length = sinString.length(); //Capturing the length of the input.
if ((length != 11) || (sinString.charAt(3)!= '-') || (sinString.charAt(7)!= '-')) //Checking for length and dashes
{
JOptionPane.showMessageDialog(null,
"You entered an invalid entry. "
+ sinString + "\nRe-enter your Social Insurance Number with dashes included.");
errstatus = 1;
}
while (length == 11)
{
if ((Character.isDigit(firstString.charAt(0))) && (Character.isDigit(firstString.charAt(1))) && (Character.isDigit(firstString.charAt(2))))
{
errstatus = 0;
}
else if ((Character.isDigit(thirdString.charAt(0))) && (Character.isDigit(thirdString.charAt(1))) && (Character.isDigit(thirdString.charAt(2))))
{
errstatus = 0;
}
if (errstatus == 0)
{
JOptionPane.showMessageDialog(null, "You entered " + sinString + "\nas your Social Insurance Number.");
}
{
while (errstatus2 == 1)
{
inputPostalCode = JOptionPane.showInputDialog(null,
"Enter your Postal code with format a9a a9a");
lengthpc = inputPostalCode.length();
if ((lengthpc != 7)|| (inputPostalCode.charAt(3)!= ' ')) //Checking for length and space in format
{
JOptionPane.showMessageDialog(null,
"You entered an invalid entry. "
+ sinString + "\nRe-enter your Postal Code with format a9a a9a.");
errstatus2 = 1;
}
while (length == 7)
{
if ((Character.isLetter(firstPcString.charAt(0))) && (Character.isDigit(firstPcString.charAt(1))) && (Character.isLetter(firstPcString.charAt(2))))
{
errstatus2 = 0;
}
if (errstatus2 == 0)
{
JOptionPane.showMessageDialog(null, "Your entered " + inputPostalCode
+ "\nas your Postal Code." );
// System.exit(0);
}
{
String status;
final String MARRIED;
final String SINGLE;
//char firstStatus;
inputStatus = JOptionPane.showInputDialog(null,
"Enter your marital status as 'Married' or 'Single'.");
// firstStatus = inputStatus.charAt(0);
if ((inputStatus.charAt(0)== 'M' ||(inputStatus.charAt(0)== 'm' ))) //Checking for marital status
{
status = MARRIED;
}
else if ((inputStatus.charAt(0)== 'S' ||(inputStatus.charAt(0)== 's' )))
{
status = SINGLE;
}
else
{
JOptionPane.showMessageDialog(null, "Your marital status was entered incorrectly.");
// System.exit(0);
}
}
{
income = JOptionPane.showInputDialog(null,
"Enter your income for the year.");
income = Double.parseDouble(inputIncome);
while (income < 0);
{
JOptionPane.showMessageDialog(null, "Your income was entered as a negative, please re-enter.");
}
if (income >= 0);
{
JOptionPane.showMessageDialog(null, "Your income was entered as " + income);
System.exit(0);
}
}
{
TaxReturn aTaxReturn = new TaxReturn(income, status);
JOptionPane.showMessageDialog(null, "The tax payable is "
+ aTaxReturn.getTax());
No (surely you could see it wasn't right after you posted it?). Put your code inside [CODE]...[/CODE] tags (where the ellipsis is). The idea is to keep the formatting so it is readable.
If you get errors, please post up the full error message text (i.e. copy & paste the whole thing).
The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents...
N. Borenstein
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
ex. "[code ] put code between these [/code]" and it makes it easier to read
Code:
[import javax.swing.*;
public class PrepareTax
/*Chapter 7, Case Project "The Tax Advantage Company", Page 263.
This is an application that prompts a user for inputs to create a Taxreturn object.
Filename is PrepareTax.java
Written by Mark DeMuynck
Wednesday, July 7, 2009
Java Version 6 Update 13 (build 1.6.0_13-b03)*/
{
public static void main(String[] args)throws Exception
{
String sinString = "999-999-999", firstString, secondString, thirdString;
firstString = sinString.substring(0, 3);
secondString = sinString.substring(4, 6);
thirdString = sinString.substring(8, 10);
String inputPostalCode = "a9a a9a", firstPcString, secondPcString;
firstPcString = inputPostalCode.substring(0, 3);
secondPcString = inputPostalCode.substring(4, 6);
String inputStatus;
String inputIncome;
double income;
char errstatus = 1;
char errstatus2 = 1;
int length;
int lengthpc;
while (errstatus == 1)
{
sinString = JOptionPane.showInputDialog(null,
"Enter your Social Insurance Number with format 999-999-999.");
length = sinString.length(); //Capturing the length of the input.
if ((length != 11) || (sinString.charAt(3)!= '-') || (sinString.charAt(7)!= '-')) //Checking for length and dashes
{
JOptionPane.showMessageDialog(null,
"You entered an invalid entry. "
+ sinString + "\nRe-enter your Social Insurance Number with dashes included.");
errstatus = 1;
}
while (length == 11)
{
if ((Character.isDigit(firstString.charAt(0))) && (Character.isDigit(firstString.charAt(1))) && (Character.isDigit(firstString.charAt(2))))
{
errstatus = 0;
}
else if ((Character.isDigit(secondString.charAt(0))) && (Character.isDigit(secondString.charAt(1))) && (Character.isDigit(secondString.charAt(2))))
{
errstatus = 0;
}
else if ((Character.isDigit(thirdString.charAt(0))) && (Character.isDigit(thirdString.charAt(1))) && (Character.isDigit(thirdString.charAt(2))))
{
errstatus = 0;
}
if (errstatus == 0)
{
JOptionPane.showMessageDialog(null, "You entered " + sinString + "\nas your Social Insurance Number.");
}
{
while (errstatus2 == 1)
{
inputPostalCode = JOptionPane.showInputDialog(null,
"Enter your Postal code with format a9a a9a");
lengthpc = inputPostalCode.length();
if ((lengthpc != 7)|| (inputPostalCode.charAt(3)!= ' ')) //Checking for length and space in format
{
JOptionPane.showMessageDialog(null,
"You entered an invalid entry. "
+ sinString + "\nRe-enter your Postal Code with format a9a a9a.");
errstatus2 = 1;
}
while (length == 7)
{
if ((Character.isLetter(firstPcString.charAt(0))) && (Character.isDigit(firstPcString.charAt(1))) && (Character.isLetter(firstPcString.charAt(2))))
{
errstatus2 = 0;
}
else if ((Character.isLetter(secondPcString.charAt(0))) && (Character.isDigit(secondPcString.charAt(1))) && (Character.isDigit(secondPcString.charAt(2))))
{
errstatus2 = 0;
}
if (errstatus2 == 0)
{
JOptionPane.showMessageDialog(null, "Your entered " + inputPostalCode
+ "\nas your Postal Code." );
// System.exit(0);
}
{
String status;
final String MARRIED;
final String SINGLE;
//char firstStatus;
inputStatus = JOptionPane.showInputDialog(null,
"Enter your marital status as 'Married' or 'Single'.");
// firstStatus = inputStatus.charAt(0);
if ((inputStatus.charAt(0)== 'M' ||(inputStatus.charAt(0)== 'm' ))) //Checking for marital status
{
status = MARRIED;
}
else if ((inputStatus.charAt(0)== 'S' ||(inputStatus.charAt(0)== 's' )))
{
status = SINGLE;
}
else
{
JOptionPane.showMessageDialog(null, "Your marital status was entered incorrectly.");
// System.exit(0);
}
}
{
income = JOptionPane.showInputDialog(null,
"Enter your income for the year.");
income = Double.parseDouble(inputIncome);
while (income < 0);
{
JOptionPane.showMessageDialog(null, "Your income was entered as a negative, please re-enter.");
}
if (income >= 0);
{
JOptionPane.showMessageDialog(null, "Your income was entered as " + income);
System.exit(0);
}
}
{
TaxReturn aTaxReturn = new TaxReturn(income, status);
JOptionPane.showMessageDialog(null, "The tax payable is "
+ aTaxReturn.getTax());
}
{
System.exit(0);
}
}
}]
import javax.swing.*;
public class PrepareTax
/*Chapter 7, Case Project "The Tax Advantage Company", Page 263.
This is an application that prompts a user for inputs to create a Taxreturn object.
Filename is PrepareTax.java
Wednesday, July 7, 2009
Java Version 6 Update 13 (build 1.6.0_13-b03)*/
{
public static void main(String[] args)throws Exception
{
String sinString = "999-999-999", firstString, secondString, thirdString;
firstString = sinString.substring(0, 3);
secondString = sinString.substring(4, 6);
thirdString = sinString.substring(8, 10);
String inputPostalCode = "a9a a9a", firstPcString, secondPcString;
firstPcString = inputPostalCode.substring(0, 3);
secondPcString = inputPostalCode.substring(4, 6);
String inputStatus;
String inputIncome;
double income;
char errstatus = 1;
char errstatus2 = 1;
int length;
int lengthpc;
while (errstatus == 1)
{
sinString = JOptionPane.showInputDialog(null,
"Enter your Social Insurance Number with format 999-999-999.");
length = sinString.length(); //Capturing the length of the input.
if ((length != 11) || (sinString.charAt(3)!= '-') || (sinString.charAt(7)!= '-')) //Checking for length and dashes
{
JOptionPane.showMessageDialog(null,
"You entered an invalid entry. "
+ sinString + "\nRe-enter your Social Insurance Number with dashes included.");
errstatus = 1;
}
while (length == 11)
{
if ((Character.isDigit(firstString.charAt(0))) && (Character.isDigit(firstString.charAt(1))) && (Character.isDigit(firstString.charAt(2))))
{
errstatus = 0;
}
else if ((Character.isDigit(secondString.charAt(0))) && (Character.isDigit(secondString.charAt(1))) && (Character.isDigit(secondString.charAt(2))))
{
errstatus = 0;
}
else if ((Character.isDigit(thirdString.charAt(0))) && (Character.isDigit(thirdString.charAt(1))) && (Character.isDigit(thirdString.charAt(2))))
{
errstatus = 0;
}
if (errstatus == 0)
{
JOptionPane.showMessageDialog(null, "You entered " + sinString + "\nas your Social Insurance Number.");
}
{
while (errstatus2 == 1)
{
inputPostalCode = JOptionPane.showInputDialog(null,
"Enter your Postal code with format a9a a9a");
lengthpc = inputPostalCode.length();
if ((lengthpc != 7)|| (inputPostalCode.charAt(3)!= ' ')) //Checking for length and space in format
{
JOptionPane.showMessageDialog(null,
"You entered an invalid entry. "
+ sinString + "\nRe-enter your Postal Code with format a9a a9a.");
errstatus2 = 1;
}
while (length == 7)
{
if ((Character.isLetter(firstPcString.charAt(0))) && (Character.isDigit(firstPcString.charAt(1))) && (Character.isLetter(firstPcString.charAt(2))))
{
errstatus2 = 0;
}
else if ((Character.isLetter(secondPcString.charAt(0))) && (Character.isDigit(secondPcString.charAt(1))) && (Character.isDigit(secondPcString.charAt(2))))
{
errstatus2 = 0;
}
if (errstatus2 == 0)
{
JOptionPane.showMessageDialog(null, "Your entered " + inputPostalCode
+ "\nas your Postal Code." );
// System.exit(0);
}
{
String status;
final String MARRIED;
final String SINGLE;
//char firstStatus;
inputStatus = JOptionPane.showInputDialog(null,
"Enter your marital status as 'Married' or 'Single'.");
// firstStatus = inputStatus.charAt(0);
if ((inputStatus.charAt(0)== 'M' ||(inputStatus.charAt(0)== 'm' ))) //Checking for marital status
{
status = MARRIED;
}
else if ((inputStatus.charAt(0)== 'S' ||(inputStatus.charAt(0)== 's' )))
{
status = SINGLE;
}
else
{
JOptionPane.showMessageDialog(null, "Your marital status was entered incorrectly.");
// System.exit(0);
}
}
{
income = JOptionPane.showInputDialog(null,
"Enter your income for the year.");
income = Double.parseDouble(inputIncome);
while (income < 0);
{
JOptionPane.showMessageDialog(null, "Your income was entered as a negative, please re-enter.");
}
if (income >= 0);
{
JOptionPane.showMessageDialog(null, "Your income was entered as " + income);
System.exit(0);
}
}
{
TaxReturn aTaxReturn = new TaxReturn(income, status);
JOptionPane.showMessageDialog(null, "The tax payable is "
+ aTaxReturn.getTax());
}
{
System.exit(0);
}
}
}
If you indent your code with a consistent style it will make it a lot easier to see where the problem is.
Look at each of the if statements, while statements etc and make sure each code block associated with the statement has exactly one opening and one closing bracket. Then do the same for each method and finally the class, deleting spurious brackets/adding missing brackets as you go.
I think I fixed your bracket problem but you have some compatability issues with the optionpane.
here is the code
Code:
import javax.swing.*;
public class PrepareTax
/*Chapter 7, Case Project "The Tax Advantage Company", Page 263.
This is an application that prompts a user for inputs to create a Taxreturn object.
Filename is PrepareTax.java
Wednesday, July 7, 2009
Java Version 6 Update 13 (build 1.6.0_13-b03)*/
{
public static void main(String[] args)throws Exception
{
String sinString = "999-999-999", firstString, secondString, thirdString;
firstString = sinString.substring(0, 3);
secondString = sinString.substring(4, 6);
thirdString = sinString.substring(8, 10);
String inputPostalCode = "a9a a9a", firstPcString, secondPcString;
firstPcString = inputPostalCode.substring(0, 3);
secondPcString = inputPostalCode.substring(4, 6);
String inputStatus;
String inputIncome;
double income;
char errstatus = 1;
char errstatus2 = 1;
int length;
int lengthpc;
while (errstatus == 1)
{
sinString = JOptionPane.showInputDialog(null,
"Enter your Social Insurance Number with format 999-999-999.");
length = sinString.length(); //Capturing the length of the input.
if ((length != 11) || (sinString.charAt(3)!= '-') || (sinString.charAt(7)!= '-')) //Checking for length and dashes
{
JOptionPane.showMessageDialog(null,
"You entered an invalid entry. "
+ sinString + "\nRe-enter your Social Insurance Number with dashes included.");
errstatus = 1;
}
while (length == 11)
{
if ((Character.isDigit(firstString.charAt(0))) && (Character.isDigit(firstString.charAt(1))) && (Character.isDigit(firstString.charAt(2))))
{
errstatus = 0;
}
else if ((Character.isDigit(secondString.charAt(0))) && (Character.isDigit(secondString.charAt(1))) && (Character.isDigit(secondString.charAt(2))))
{
errstatus = 0;
}
else if ((Character.isDigit(thirdString.charAt(0))) && (Character.isDigit(thirdString.charAt(1))) && (Character.isDigit(thirdString.charAt(2))))
{
errstatus = 0;
}
}
if (errstatus == 0)
{
JOptionPane.showMessageDialog(null, "You entered " + sinString + "\nas your Social Insurance Number.");
}
}
while (errstatus2 == 1)
{
inputPostalCode = JOptionPane.showInputDialog(null,
"Enter your Postal code with format a9a a9a");
lengthpc = inputPostalCode.length();
if ((lengthpc != 7)|| (inputPostalCode.charAt(3)!= ' ')) //Checking for length and space in format
{
JOptionPane.showMessageDialog(null,
"You entered an invalid entry. "
+ sinString + "\nRe-enter your Postal Code with format a9a a9a.");
errstatus2 = 1;
}
while (length == 7)
{
if ((Character.isLetter(firstPcString.charAt(0))) && (Character.isDigit(firstPcString.charAt(1))) && (Character.isLetter(firstPcString.charAt(2))))
{
errstatus2 = 0;
}
else if ((Character.isLetter(secondPcString.charAt(0))) && (Character.isDigit(secondPcString.charAt(1))) && (Character.isDigit(secondPcString.charAt(2))))
{
errstatus2 = 0;
}
}
if (errstatus2 == 0)
{
JOptionPane.showMessageDialog(null, "Your entered " + inputPostalCode
+ "\nas your Postal Code." );
// System.exit(0);
}
}
String status;
final String MARRIED;
final String SINGLE;
//char firstStatus;
inputStatus = JOptionPane.showInputDialog(null,
"Enter your marital status as 'Married' or 'Single'.");
// firstStatus = inputStatus.charAt(0);
if ((inputStatus.charAt(0)== 'M' ||(inputStatus.charAt(0)== 'm' ))) //Checking for marital status
{
status = MARRIED;
}
else if ((inputStatus.charAt(0)== 'S' ||(inputStatus.charAt(0)== 's' )))
{
status = SINGLE;
}
else
{
JOptionPane.showMessageDialog(null, "Your marital status was entered incorrectly.");
// System.exit(0);
}
income = JOptionPane.showInputDialog(null, "Enter your income for the year.");
income = Double.parseDouble(inputIncome);
while (income < 0);
{
JOptionPane.showMessageDialog(null, "Your income was entered as a negative, please re-enter.");
}
if (income >= 0);
{
JOptionPane.showMessageDialog(null, "Your income was entered as " + income);
System.exit(0);
}
TaxReturn aTaxReturn = new TaxReturn(income, status);
JOptionPane.showMessageDialog(null, "The tax payable is "
+ aTaxReturn.getTax());
System.exit(0);
}
}
Thanks, that was an error in the code. I still get a "PrepareTax.java:151: reached end of file while parsing" error though. I'm sure that it has something to do with the brackets.
Sorry I didn't read the post prior. I think that did fix the bracket issue and the problem in the JOption pane. Now it cannot find symbol class TaxReturn, so almost there.
Thanks a lot, I was pretty frustrated.
I am still struggling with it, especially the syntax with having to do all the data validation that is required. There is a lot of validation to do for a intro course. We are using Java Programming 4th edition by Joyce Farrell. I assume you are too. I find that the exercises are not well supported by the chapters. All the code in the book does one thing, and then the exercise asks you to do multiple things without an example to go by.
I have learned more off the internet than in the course.
How are you doing?
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.