I am almost complete this assignment. But I am stuck with line 108 error. Could someone please help me out on this?

import java.io.*;
public class Assignment4
{
	public static void main(String[]args) throws IOException
	{
		//delcare and construct variables
		int marStatus, status, gross, earn, excess, annual;
		double fica, medicare, net;
		BufferedReader dataIn= new BufferedReader(new InputStreamReader(System.in));

		//print prompts and get input
		System.out.print("Enter your relationship status (1)Single, or (2)Married. ");
		marStatus = Integer.parseInt(dataIn.readLine());
		status = marStatus;

		System.out.print("Enter your Annual Salary: $");
		gross = Integer.parseInt(dataIn.readLine());
		annual = gross;

///////////////////////////////////////////////////////////////////////////////////////

				System.out.println("Weekly Gross: $" + (annual/52));
				earn = annual/52;
				System.out.println("FICA (Social Security Tax): $" + (earn * .062));
				fica = earn * .062;
				System.out.println("Medicare Tax: $" + (earn *.0145));
				medicare = earn *.0145;
///////////////////////////////////////////////////////////////////////////////////////
		     {
				// for single
		     	if (status==1)
		     	{
		     	if (earn <= 116)
		     		{
		            	System.out.println("The amount to withhold is $0.0");
		        	}
		        else if (earn>=116 && earn<=200)
		        	{
						excess = (earn-116);
						System.out.println("Excess earnings over wage bracket : $" + (excess));
						System.out.println("Federal Income Tax :$" + (excess * .10));
						net = (excess * .10);
		        	}
		        else if (earn>=200 && earn<=693)
					{
						excess = (earn-200);
						System.out.println("Excess earnings over wage bracket : $" + (excess));
						System.out.println("Federal Income Tax :$" + (8.40+(excess*.15)));
						net = (8.40+(excess*.15));
		        	}
		        else if (earn>=639 && earn<=1302)
		        	{
						excess = (earn-639);
						System.out.println("Excess earnings over wage bracket : $" + (excess));
						System.out.println("Federal Income Tax :$" + (82.35+(excess*.25)));
						net = (82.35+(excess*.25));
		        	}
		        else if (earn>=1302)
					{
						excess = (earn-1302);
						System.out.println("Excess earnings over wage bracket : $" + (excess));
						System.out.println("Federal Income Tax :$" + (234.50+(excess*.27)));
						net = (234.50+(excess*.27));
		        	}
				}


				// for married
		     	if (status==2)
		     	{
		     	if (earn <= 264)
		     		{
		            	System.out.println("The amount to withhold is $0.0");
		        	}
		        else if (earn>=264 && earn<=471)
		        	{
						excess = (earn-264);
						System.out.println("Excess earnings over wage bracket : $" + (excess));
						System.out.println("Federal Income Tax :$" + (excess * .10));
						net = (excess * .10);
		        	}
		        else if (earn>=471 && earn<=1457)
					{
						excess = (earn-471);
						System.out.println("Excess earnings over wage bracket : $" + (excess));
						System.out.println("Federal Income Tax :$" + (20.70+(excess*.15)));
						net = (20.70+(excess*.15));
		        	}
		        else if (earn>=1457 && earn<=1809)
		        	{
						excess = (earn-1457);
						System.out.println("Excess earnings over wage bracket : $" + (excess));
						System.out.println("Federal Income Tax :$" + (168.60+(excess*.25)));
						net = (168.60+(excess*.25));
		        	}
		        else if (earn>=1809)
					{
						excess = (earn-1809);
						System.out.println("Excess earnings over wage bracket : $" + (excess));
						System.out.println("Federal Income Tax :$" + (256.60+(excess*.27)));
						net = (256.60+(excess*.27));
		        	}
				}

			}
//////////////////////////////////////////////////////////////////////////////////////////////////////

				System.out.println("Net Paycheck: $" + (earn-fica-medicare-net));

	}
}

Hi there,

Just at first glance... your variable net has not been initialized, try assigning a default value to it and see if that fixes the problem. Though, next time try to be a little more specific about the errors you are receiving. "The local variable net may not have been initialized" instead of "line 108 error" would be a lot more helpful, for instance.

Good luck with your assignment,

Traevel

default value fix the problem, but I want it to get the Net value from if else if statement, instead of making it one value.

If you initialized net in the declaration it should be able to be updated unless it was made final I ran your code after initializing net and after entering 1 and 15000 received the following result:

Enter your relationship status (1)Single, or (2)Married. 1
Enter your Annual Salary: $15000
Weekly Gross: $288
FICA (Social Security Tax): $17.856
Medicare Tax: $4.176
Excess earnings over wage bracket : $88
Federal Income Tax :$21.6
Net Paycheck: $244.36800000000002

Perhaps it needs rounding, but it's definitely not returning the default value I gave it.

Change line 8 in your code to include a value and it should work.

Good luck,

Traevel

edit: By the way, I forgot to mention that net had a default value of 0 and returned 21.6 in the end.

So on line 8. Am I suppose to make it like this

double fica, medicare, net = 0;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.