Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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:

 




1
50000


2
60000


3
70000


4
80000


5
90000


6
100000


7
110000


8
120000


9
130000


10
140000

 

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 ??

  

Step by Step Solution

3.39 Rating (177 Votes )

There are 3 Steps involved in it

Step: 1

To parse an XML file in Java you typically use libraries like DOM Document Object Model or SAX Simple API for XML Since your XML file seems relatively ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems analysis and design

Authors: kenneth e. kendall, julie e. kendall

8th Edition

135094909, 013608916X, 9780135094907, 978-0136089162

More Books

Students also viewed these Programming questions

Question

What are the attributes of a technical decision?

Answered: 1 week ago

Question

How do the two components of this theory work together?

Answered: 1 week ago

Question

How does MIS differ from DSS?

Answered: 1 week ago

Question

Draw a context-level data flow diagram for Perfect Pizza.

Answered: 1 week ago