QuestionQuestion

Assignment 1:
For this Assignment, submit the following program:
The following code creates a simple ArrayList:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Ex01 {
    public static void main(String[] args) throws IOException {
       BufferedReader userInput = new BufferedReader
            (new InputStreamReader(System.in));
       ArrayList<String> myArr = new ArrayList<String>();
       myArr.add("Zero");
       myArr.add("One");
       myArr.add("Two");
       myArr.add("Three");      
    }
}
Starting with this provided code, add the following functionality:
Add items to the ArrayList, one at a time, based on user typed input. The user will be prompted for the String to be stored in the ArrayList and then hit enter. The user will be able to continue to add items to the ArrayList until they just hit enter without typing anything.
Once the user does this (hits enter without typing anything), the program will display all of the elements of the ArrayList, both the index and String values, in a table. It will do this via a single loop.
Compile, run, and check the results. Submit the following:
The source file for each of the classes created (If more than one file has been created, zip them into one .zip file for posting.)
An MS .doc file with explanations/comments of your solution and the results of a test run, including a screen shot picture.


Assignment 2:
For this Assignment, submit the following program:
The following code causes an exception error:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Ex02 {
    public static void main(String[] args) throws IOException {
       BufferedReader userInput = new BufferedReader
            (new InputStreamReader(System.in));
       ArrayList<String> myArr = new ArrayList<String>();
       myArr.add("Zero");
       myArr.add("One");
       myArr.add("Two");
       myArr.add("Three");      
       System.out.println(myArr.get(4));            
    }
}
Starting with this provided code, add the following functionality:
Use a Try/Catch block so that the exception is caught and the program exits a bit more gracefully. Save this file as TryCatch.java. (Be sure to rename the Public Class accordingly.)
Starting with the provided code again (without the Try/Catch block), fix the code so that it runs correctly. That is to say, it should display the last item in the ArrayList. Save this file as Fixed.java. (Be sure to rename the Public Class accordingly.)
Compile, run, and check the results. Submit the following:
The source file for each of the classes created (If more than one file has been created, zip them into one .zip file for posting.)
An MS .doc file with explanations/comments of your solution and the results of a test run, including a screen shot picture.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Ex01 {
    public static void main(String[] args) throws IOException {
       BufferedReader userInput = new BufferedReader
       (new InputStreamReader(System.in));
       ArrayList<String> myArr = new ArrayList<String>();
       myArr.add("Zero");
       myArr.add("One");
       myArr.add("Two");
       myArr.add("Three");
      
       String input;
       // get first input
       System.out.println("Enter a string to be stored in the ArrayList: ");
       input = userInput.readLine();
       // ask for value until the user hit enter button without entering any charater
       while (!input.isEmpty()) {                        
            myArr.add(input);
            System.out.println("Enter a string to be stored in the ArrayList: ");
            input = userInput.readLine();
       }...
$28.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats