hi..
this is my new program ..
i want a fix or constant answer like,
when the answer in:
Student Name: Monica Clare
then it proceed to another question..
but when..
Student Name: blah blah
then. it shown error_message that it is invalid answer,, ..

please help me debugging this .. thanks ^_^

import javax.swing.*;
import java.util.*;
import java.awt.Graphics;
import java.util.Random;
import java.io.*;   
import java.util.regex.Pattern;
import java.util.regex.Matcher;


public class Final

{
   
	public static void main(String args[])
		 
	{
		String name,student,courses,answer,result,e,f,s="";
		

do{

		Scanner Console = new Scanner(System.in);
		name=JOptionPane.showInputDialog("Student Name:");
		student=JOptionPane.showInputDialog("Student I.D.:");
		courses=JOptionPane.showInputDialog("No. of courses enrolled:");
		e=JOptionPane.showInputDialog("Total No. of credit hours:");
	    f=JOptionPane.showInputDialog("Remaining Bills upon Enrollment:");
	   
	      
    	
		result="\n\tStudent Name: "+name+"\n\tStudent I.D.: "+student+"\n\tNo. of courses enrolled: "+courses+"\n\tTotal No. of credit hours: "+e+".";
	    answer = JOptionPane.showInputDialog("Is tuition paid? [Y/N]:");
 
	  

	   
	   
	   
	   
		if (answer.charAt(0) == 'Y' || answer.charAt(0) == 'y');
			
	    else
	  
	    JOptionPane.showMessageDialog(null,"Paid your Remaining Bill","Warning",
	    JOptionPane.ERROR_MESSAGE);	
		
			
		}while (answer.charAt(0)=='N' || answer.charAt(0)=='n');
		
		JOptionPane.showMessageDialog(null,result,"Result",
	    JOptionPane.PLAIN_MESSAGE);

		
	   JOptionPane.showMessageDialog(null, "Done", "Done", JOptionPane.INFORMATION_MESSAGE);
	    
	}
}

As I mentioned in your last thread, you need to define what an "invalid" answer is and what a "valid" answer is. It looks like you have decided to use regular expressions to do this, which is a good idea, but again, you and only you can decide what's "valid" and "invalid". From there, build your regular expression. Here are links to tutorials that you may find useful:

http://java.sun.com/docs/books/tutorial/essential/regex/
http://www.java2s.com/Tutorial/Java/0130__Regular-Expressions/Primitiveaddressvalidation.htm
http://www.java2s.com/Tutorial/Java/0120__Development/Validatethefirstnameandlastname.htm
http://www.zparacha.com/java_regex_validation/

A valid name might consist of two or three words where all characters are letters or '.' or an apostrophe. You may require the first letter and only the first letter to be capitalized. It's up to you whether you deal with stuff like:

Joseph McManus
Patrick O'Brien
Osama bin Laden (the only name I could think of where a word wasn't capitalized)

You need to decide on some rules.

Two or Three words?

Billy Joe Jim Bob Thornton

;-)

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.