I am working on an internship assignment and I am having a problem with an exception. Im using the DOM method and have thrown the SAX exception anyway in the main, but i keep getting the error
CoefficientCalculator.java:13: error: cannot find symbol
public static void main(String[] args)throws ParserConfigurationException, SAXException, IOException
^
symbol: class SAXException
location: class CoefficientCalculator
1 error
When I remove the throwing of the exception I get additional errors. The remainder of the code is posted below. Any ideas?
import org.w3c.dom.*;
import javax.xml.parsers.*;
import java.io.*;
public class CoefficientCalculator{
public static void main(String[] args)throws ParserConfigurationException, SAXException, IOException
{
double creditScoreAcc = 0;
double creditSquared;
double paybackPctAcc = 0;
double paybackPctSquared;
double xcrossy;
double coefficient;
int itemCount = 0;
String input1;
String input2;
//Create the Document Builders
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
//Build the document
Document document = builder.parse(new File("SampleData.xml"));
//Normalize the XML structure
document.getDocumentElement().normalize();
//Get and dislplay root node
Element root = document.getDocumentElement();
System.out.println(root.getNodeName());
//Find mean of credit scores
NodeList list = document.getElementsByTagName("Funding");
for(int i = 0; i < list.getLength(); i++){
Node node =list.item(i);
if(node.getNodeType() == Node.ELEMENT_NODE){
Element element = (Element) node;
input1 = element.getAttribute("creditScore");
double a = Double.parseDouble(input1);
input2 = element.getAttribute("totPymtPct");
double b = Double.parseDouble(input2);
if(a > 0){
creditScoreAcc += a;
paybackPctAcc += b;
itemCount++;
}
}
}
creditSquared = Math.pow(creditScoreAcc, 2.0);
paybackPctSquared = Math.pow(paybackPctAcc, 2.0);
xcrossy = creditScoreAcc * paybackPctAcc;
coefficient = CalcCoefficient(creditScoreAcc, paybackPctAcc, xcrossy,
creditSquared, paybackPctSquared, itemCount);
}
//Method to calculate to Correlation Coefficient of two data sets
public static double CalcCoefficient(double x, double y, double xy, double x2, double y2, int n){
double c = (n)*(xy)-(x * y)/Math.sqrt(n*x2-(Math.pow(x, 2.0)))*Math.sqrt(n*y2-(Math.pow(y, 2.0)));
return c;
}
}
No comments:
Post a Comment