954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Orpaned case

I have a orpaned case error and im not sure where i am missing anything. Probably just needs another set of eyes to find it. thank you in advance

Here is the error code :
C:\Users\winte497\Documents\FSMValue.java:109: orphaned case
case 6: if ((ch >= '0') && (ch <= '9'))

Here is my program:

import java.util.*;
public class FSMValue {

  public static void main(String[] args) {

	int x;
	String s;
	char ch;
	int state;
	double value;
	double whole_part, dece_part;
	int sign,power;
	Scanner input = new Scanner ( System.in );

	System.out.print("Enter Number or enter CTRL z to exit =====> ");
	while (input.hasNext())
	{
 		s = input.nextLine();
 		s = s + ' ';
 		x = 0;
 		state =1;
 		value =0;
 		whole_part =0;
 		dece_part = 0;
 		sign =1;
 		power =10;
		while ((state != 7) & (state != 6))
		{
			ch=s.charAt(x++);
			System.out.print(ch);
			switch (state)
			{
			case 1:	if ((ch >= '0') && (ch <= '9'))
					{
					state = 3;
					whole_part = whole_part + (int)ch-(int)'0';
					}
				else
					if ((ch == '+') || (ch == '-'))
						{
						state =2;
						if (ch == '-')
							sign =-1;
						}
					else
						{
							state = 7;
							System.out.println(" <== Loooky what we got here. Digit, +, or - expected ");
						}
				break;

			case 2:	if ((ch >= '0') && (ch <= '9'))
					{
					state = 3;
					whole_part = whole_part+ (int)ch-(int)'0';
					}
				else
					{
						state = 7;
						System.out.println(" <== Loooky what we got here. Digit expected ");
					}
				break;

			case 3:	if ((ch >= '0') && (ch <= '9'))
					{
					state = 3;
					whole_part = whole_part*10 + (int)ch-(int)('0');
					}
				else
					if (ch == '.')
						state = 4;
					else
						if (ch == ' ')
							state =6;
						else
						{
							state = 7;
							System.out.println(" <== Loooky what we got here. Digit, Blank or Period expected ");
						}
				break;

			case 4:	if ((ch >= '0') && (ch <= '9'))
					{
					state = 5;
					dece_part += (int)ch-(int)('0');
					}
				else
					{
						state = 7;
						System.out.println(" <== Loooky what we got here. Digit expected ");
					}
				break;

			case 5:	if ((ch >= '0') && (ch <= '9'))
					{
					state = 5;
					dece_part = dece_part*10 + (int)ch-(int)('0');
					power = power *10;
					}
				else
					if (ch == ' ')
							state =6;
					else
						{
							state = 7;
							System.out.println("  <== Loooky what we got here. Digit or Blank expected ");

			case 6:	if ((ch >= '0') && (ch <= '9'))
					{
					state = 3;
					whole_part = whole_part + (int)ch-(int)'0';
					}
					else
						if ((ch == 'e') || (ch == 'E'))
					{
							state =2;
						if (ch == 'e')

					}
					else
							state = 7;
							System.out.println(" <== Loooky what we got here. e or E expected ");
					}
					break;

					}
			case 7:	if ((ch >= '0') && (ch <= '9'))
					{
					state = 5;
					dece_part += (int)ch-(int)('0');
					}
					else
					{
						state = 7;
						System.out.println(" <== Loooky what we got here. Digit expected ");
					}
				break;

			} //end switch
		} // end while state

		if (state ==6)
			{
			System.out.println(" <=== This Parsing was Successful");
			System.out.printf("%s%6.2f", " The value of the number is = ",sign *(whole_part + dece_part/power));
			}
		System.out.print("\n-----------------------------------\n");
		System.out.print("\nEnter Number or enter CTRL z to exit =====> ");
	} // end while end of file

} // end of main method
} // end of class
chriswinter
Light Poster
25 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

well ... no offence, but you've made a mess out of your usage of
{'s and }'s.

starting from line 108.

not to mention the fact that you're using variables you didn't declare or initialize.
you may want to spend some minutes cleaning your code.

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

You don't close the else block of case 5.

Always use braces when using if and you won't forget this sort of thing.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

Thank you for your help

chriswinter
Light Poster
25 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You