This is my code:
import javax.swing.JOptionPane ; import java.util.Date ; public class blahblah { // *************************************************************************main public static void main(String[] args) { String province ; province = getGoodProvinceCode() ; }// close main // *********************************************************************getPST public static String getPST(String province) { final double GST = 0.05 ; final double AB_PST = 0.0 ; // AB provincial sales tax final double BC_PST = 0.07 ; // BC provincial sales tax final double MB_PST = 0.07 ; // MB provincial sales tax final double NB_PST = 0.08 ; // NB provincial sales tax final double NL_PST = 0.08 ; // NL provincial sales tax final double NS_PST = 0.08 ; // NS provincial sales tax final double ON_PST = 0.08 ; // ON provincial sales tax final double PE_PST = 0.10 ; // PE provincial sales tax final double QC_PST = 0.075 ; // QC provincial sales tax final double SK_PST = 0.05 ; // SK provincial sales tax double pst ; double gst ; double hst ; String prov ; province = getGoodProvinceCode() ; // find tax rates gst = GST ; hst = pst = 0. ; if ( province.equals("AB") ) pst = 0. ; else if ( province.equals("BC") ) pst = BC_PST; else if ( province.equals("MB") ) pst = MB_PST; else if ( province.equals("NB") ) { pst = gst = 0; hst = GST + NB_PST ; } else if ( province.equals("NL") ) { pst = gst = 0; hst = GST + NL_PST ; } else if ( province.equals("NS") ) { pst = gst = 0; hst = GST + NS_PST ; } else if ( province.equals("ON") ) pst = ON_PST; else if ( province.equals("PE") ) pst = PE_PST; else if ( province.equals("QC") ) pst = QC_PST; else if ( province.equals("SK") ) pst = SK_PST; else pst = -1 ; if ( hst > 0 ) { prov = ("H" + hst) ; } else if ( hst == 0 ) { prov = ("P" + pst) ; } else { prov = ("") ; } return prov ; }// close getPST // *********************************************************************getGoodProvinceCode public static String getGoodProvinceCode() { String prompt ; String errorMsg ; String provinceC = "" ; String prov ; String province = "" ; boolean inputOk ; // input province prompt = "Enter two-letter province abbreviation (e.g., MB)" ; inputOk = false ; errorMsg = "" ; prov = getPST(province) ; while ( ! inputOk ) { provinceC = JOptionPane.showInputDialog(null, errorMsg + prompt) ; provinceC = provinceC.toUpperCase().trim() ; if ( prov.equals("") ) { errorMsg = "Input " + provinceC + " is not a valid province abbreviation\n" ; System.out.println( errorMsg ) ; } else { inputOk = true ; } } return provinceC ; }// close getGoodProvinceCode }// close class
I get this error:
Exception in thread "main" java.lang.StackOverflowError at ChurchAustinA3Q1.getGoodProvinceCode(ChurchAustinA3Q1.java:101) at ChurchAustinA3Q1.getPST(ChurchAustinA3Q1.java:48) at ChurchAustinA3Q1.getGoodProvinceCode(ChurchAustinA3Q1.java:111) at ChurchAustinA3Q1.getPST(ChurchAustinA3Q1.java:48) at ChurchAustinA3Q1.getGoodProvinceCode(ChurchAustinA3Q1.java:111) ...etc...
I think I am getting an error because getGoodProvinceCode() calls getPST(String province), and then getPST(String province) calls getGoodProvinceCode(). I just don't know how to fix this loop.
EDIT/ Is it possible to return a variable in the middle of a method without ending the method at that point?