Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA Complete the following programs. * Baseball - again Build an XML document u

ID: 3831976 • Letter: J

Question

JAVA

Complete the following programs.

* Baseball - again

Build an XML document using stats file.

Read the new XML document into a list

Calculate and display the batting average for each player

* Web Service

Create a Java application [i]that uses the GetAtomicNumber web services from http://www.webservicex.net/New/Home/ServiceDetail/19

Requirements

When a user selects an element name, the screen draws up the element as shown on the periodic table. The information for that element will appear as shown below. I want a box output for the atomic number, Symbol, and Atomic Weight. If desired, you can display the other information

Make sure you make the form look especially good. Have titles, color, …

My output is on the second page. It resembles an entry on a periodic table of the elements.

[i] (old link) http://www.webservicex.net/WS/WSDetails.aspx?WSID=19&CATID=7.

Bonus

Use the GetAtoms webservice to populate a drop-down box with all the Element names

Explanation / Answer

-Extensible Markup Language, XML is a very popular simple text based language to be used as a mode of communication between the applications.

-It is considered as a standard means to transport and store data.

-JAVA provides an excellent support and rich set of libraries to parse, modify or inquire XML documents.

Here I am providing the code for xml creation using java

import org.w3c.dom.Attr;

import org.w3c.dom.Document;

import org.w3c.dom.Element;

import java.io.File;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.parsers.ParserConfigurationException;

import javax.xml.transform.Transformer;

import javax.xml.transform.TransformerException;

import javax.xml.transform.TransformerFactory;

import javax.xml.transform.dom.DOMSource;

import javax.xml.transform.stream.StreamResult;

public class buildXMLFile {

        public static void main(String argv[]) {

        try {

DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();

               DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

       

               Document doc = docBuilder.newDocument();

                Element rootElement = doc.createElement("company");

               doc.appendChild(rootElement);

              

               Element cricket = doc.createElement("cricket");

               rootElement.appendChild(ele);

              

               Attr atr = doc.createAttribute("id");

               atr.setValue("10");

               cricket.setAttributeNode(atr);

              

               // bat details

               Element bat = doc.createElement("bat");

               bat.appendChild(doc.createTextNode("MRF"));

               staff.appendChild(firstname);

               // ball details

               Element ball = doc.createElement("ball");

               ball.appendChild(doc.createTextNode("cork"));

               cricket.appendChild(lastname);

              

               // write the content into xml file

               TransformerFactory transformerFactory = TransformerFactory.newInstance();

               Transformer transformer = transformerFactory.newTransformer();

               DOMSource src = new DOMSource(doc);

               StreamResult res = new StreamResult(new File("E:\TPM.xml"));

               //RESULT IS IN FILE

               transformer.transform(src, res);

               System.out.println("END OF FILE");

        } catch (ParserConfigurationException pce) {

               pce.printStackTrace();

        } catch (TransformerException tfe) {

               tfe.printStackTrace();

        }

        }

}

To read an XML file I will provide an easy way

import org.w3c.dom.Attr;

import org.w3c.dom.Document;

import org.w3c.dom.Element;

import java.io.File;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.parsers.ParserConfigurationException;

import javax.xml.transform.Transformer;

import javax.xml.transform.TransformerException;

import javax.xml.transform.TransformerFactory;

import javax.xml.transform.dom.DOMSource;

import javax.xml.transform.stream.StreamResult;