I need to make this code read a .xml file. I created the .xml file in word
Question:
I need to make this code read a .xml file. I created the .xml file in word and saved it as a .xml file. I put it in the corresponding NetBeans Project File but it keeps showing errors when I run it. Please help me to get this working. ???
This is the code I have so far:
package lab.pkg9.salesperson.bonus;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class Lab9SalespersonBonus {
/**
* @param args the command line arguments
* @throws java.io.IOException
*/
public static void main(String args[]) throws IOException
{
double sales;
double totalSales = 0.0;
double totalBonus = 0.0;
double bonus;
try{
//Open the file for reading Purpose
FileReader fin = new FileReader("Salesperson.xml");
//Scanner Class Instance
Scanner Keyboard = new Scanner(fin);
while (Keyboard.hasNext())
{
//Read the Sale from the File
sales = Keyboard.nextDouble();
totalSales = totalSales + sales; //To get the total sales
if(sales>=6000.00)
{
bonus = 0.05 * sales; //to find bonus
totalBonus = totalBonus + bonus;
}
else
{
bonus = 0.02 * sales; //to find bonus
totalBonus = totalBonus + bonus;
}
}
//Close the file
fin.close();
//Print the total Sales and Bonus
System.out.println("$" + String.format("%.2f",totalSales));
System.out.println("$" + String.format("%.2f",totalBonus));
}
//if the File is not found
catch(FileNotFoundException fe)
{
System.out.println("FileNotFoundException : " + fe);
}
}
}
This is the .xml file content:
I know I am supposed to parse this but I can not figure out what do do to get it to work. Not sure how to parse.
Please help ??
Systems analysis and design
ISBN: 978-0136089162
8th Edition
Authors: kenneth e. kendall, julie e. kendall