Programming
University of Manitoba JAVA Programming and Software Engineering Program

University of Manitoba

Question Description

Need help with my Java question - I’m studying for my class.

Hi Guys

The program must have these requirements-

**Program will read file Xml File using library file java.beans.XMLDecoder also use IOException library to throw file error if not found.

**Use .readObject and .writeObject methods to read and write XML file

**the Program will Store each String from XML file into an array list and display each name.

**Modify this program into two ways as mentioned in file.

**Also can use following libraries plus create constructors, getters and setters if needed

-import java.io.ObjectInputStream;

-import java.io.FileInputStream;

-import java.util.ArrayList;

if you have any confusions please ask me before starting the Task.

use the following lab10.XML and TotalNumber.java files to support this program

Unformatted Attachment Preview

ACS-1904-002 Lab #10 Due by Saturday March 21 at 11:59 pm - Submit your .java file via Nexus - Include your name and student number in each file as a comment Create a program called ReadNamesFromXML that reads the file lab10.xml (uploaded in Nexus), stores each string of the file into an array list and displays each name. On the documentation page for XMLDecoder you will find that exceptions can arise when this program runs: FileNotFoundException: when the XMLDecoder object is created. ArrayIndexOutOfBoundsException: when the input stream has no more objects. For this exception you need the import: java.lang.ArrayIndexOutOfBoundsException. ● ● Modify this program in two ways: a. it should terminate with a message ”file not found” if a FileNotFoundException occurs. b. assume you do not know how many names are in the file -- it should read as many names as the file holds. - Use ArrayIndexOutOfBoundsException to accomplish this Submit your java file (ReadNamesFromXML.java)via Nexus. ______________________________________________________________________________ EXTRA WORK: Do not submit The program TotalNumbers (uploaded in Nexus) prompts the user to enter numbers until the user signals they are finished with "q", then the system returns the sum of the numbers. A user can easily mistype an integer (i.e. pressing a non-numeric key) and the program would fail abruptly with a NumberFormatException (on the documentation page for Integer, see parseInt). Modify the program to handle such an error: inform the user that the input was invalid and prompt the user to re-enter the number. import java.util.Scanner; public class TotalNumbers{ public static void main (String[] args) { int total = 0, n = 0; Scanner kb = new Scanner (System.in) ; System.out.println ("Enter a number (q to quit): ") ; String input = kb . next () ; while (!input.equals("q")) { n = Integer.parseInt(input) ; total += n; System.out.println("Enter a number (q to quit):") ; input = kb.next(); } System.out.println("The total of numbers is "+ total) ; } } Harry Ron Hermione Luna Draco Neville Seamus Ginny Fred George import java.util.Scanner; public class TotalNumbers{ public static void main (String[] args) { int total = 0, n = 0; Scanner kb = new Scanner (System.in) ; System.out.println ("Enter a number (q to quit): ") ; String input = kb . next () ; while (!input.equals("q")) { n = Integer.parseInt(input) ; total += n; System.out.println("Enter a number (q to quit):") ; input = kb.next(); } System.out.println("The total of numbers is "+ total) ; } } ...
Purchase answer to see full attachment
Student has agreed that all tutoring, explanations, and answers provided by the tutor will be used to help in the learning process and in accordance with Studypool's honor code & terms of service.

Final Answer

At...

JasonKirk (1186)
Duke University

Anonymous
Thanks for the help.

Anonymous
Outstanding. Studypool always delivers quality work.

Anonymous
Tutor was very helpful and took the time to explain concepts to me. Very responsive, managed to get replies within the hour.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4
Similar Questions
Related Tags