Hello, everybody,

I am doing my Java homework and we used this line in class with no problems at, I have the code from the program we used in class and it works on my computer no problem. However, when I put it into my homework's code, it gives me an error. cannot find symbol finish(). What am I doing wrong? I'm using Textpad, by the way, if that matters.

import javax.swing.JOptionPane;

public class MyType
{
	public static void main(String[] args)
	{
		String strChoice, strTryString, strTryInt, strTryDouble;
		int choice, tryInt;
		double tryDouble;
		boolean done = false;

		while(!done)
		{
			try
			{
				strChoice = JOptionPane.showInputDialog(null, "What\'s my type?\n\n1) String\n2) integer\n3) double\n4) Quit the program");

				if(strChoice == null)
					finish(); //this line gets an error

				choice = Integer.parseInt(strChoice);
				switch(choice)
				{
					case 1:
						JOptionPane.showMessageDialog(null, "You are correct. Any input can be saved as a String.");
						break;
					case 2:
						tryInt = Integer.parseInt(strChoice);
						JOptionPane.showMessageDialog(null, "You are correct.");
						break;
					case 3:
						tryDouble = Double.parseDouble(strChoice);
						JOptionPane.showMessageDialog(null, "You are correct.");
						break;
					case 4:
						done = true;
						JOptionPane.showMessageDialog(null, "Goodbye.");
						break;
					default:
						throw new NumberFormatException();
				}
			}
			catch(NumberFormatException e)
			{
				JOptionPane.showMessageDialog(null, "You need to enter a number between 1 and 4. Try again", "Error", JOptionPane.INFORMATION_MESSAGE);
			}
		}
	}
}

Your program doesn't know what finish is. You need a method that called finish that tells it what to do.

Hello, everybody,

I am doing my Java homework and we used this line in class with no problems at, I have the code from the program we used in class and it works on my computer no problem. However, when I put it into my homework's code, it gives me an error. cannot find symbol finish(). What am I doing wrong? I'm using Textpad, by the way, if that matters.

import javax.swing.JOptionPane;

public class MyType
{
	public static void main(String[] args)
	{
		String strChoice, strTryString, strTryInt, strTryDouble;
		int choice, tryInt;
		double tryDouble;
		boolean done = false;

		while(!done)
		{
			try
			{
				strChoice = JOptionPane.showInputDialog(null, "What\'s my type?\n\n1) String\n2) integer\n3) double\n4) Quit the program");

				if(strChoice == null)
					finish(); //this line gets an error

				choice = Integer.parseInt(strChoice);
				switch(choice)
				{
					case 1:
						JOptionPane.showMessageDialog(null, "You are correct. Any input can be saved as a String.");
						break;
					case 2:
						tryInt = Integer.parseInt(strChoice);
						JOptionPane.showMessageDialog(null, "You are correct.");
						break;
					case 3:
						tryDouble = Double.parseDouble(strChoice);
						JOptionPane.showMessageDialog(null, "You are correct.");
						break;
					case 4:
						done = true;
						JOptionPane.showMessageDialog(null, "Goodbye.");
						break;
					default:
						throw new NumberFormatException();
				}
			}
			catch(NumberFormatException e)
			{
				JOptionPane.showMessageDialog(null, "You need to enter a number between 1 and 4. Try again", "Error", JOptionPane.INFORMATION_MESSAGE);
			}
		}
	}
}

Is there a finish method in the other codes?
If so put it in this class too or just create a method finish()

Oh... duh >.> I was thinking it was some kind of system command... thanks.

And a pox on you too :P

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.