Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Part 1: If you have not yet submitted the solutions to Lab 5, please include those in this week's submission. If you have already submitted Lab 5, no need to repeat the submission.

Part 2: ArrayLists- Here's a simple test program that creates an ArrayList of String objects and manipulates them. Try it out. Make modifications to the method calls and understand their operations.
No submission required for this exercise.
Warning: Cutting and pasting the code may cause syntax errors!

import java.util.ArrayList; public class ArrayListTest {
public static void main(String[] args) {
ArrayList list = new ArrayList(); // Create a list

// Add elements to the list list.add("America"); // Add it to the list System.out.println("(1) " + list);

list.add(0, "Canada"); // Add it to the beginning of the list System.out.println("(2) " + list);

list.add("Russia"); // Add it to the end of the list System.out.println("(3) " + list);

list.add("France"); // Add it to the end of the list System.out.println("(4) " + list);

list.add(2, "Germany"); // Add it to the list at index 2 System.out.println("(5) " + list);

list.add(5, "Norway"); // Add it to the list at index 5 System.out.println("(6) " + list);

// Remove elements from the list
list.remove("Canada"); // Same as list.remove(0) in this case System.out.println("(7) " + list);

list.remove(2); // Remove the element at index 2 System.out.println("(8) " + list);

list.remove(list.size() - 1); // Remove the last element System.out.println("(9) " + list);

if (list.contains("France"))
System.out.println("France found at index: " + list.indexOf("France"));

System.out.println("What is the element at index 1 ? : " + list.get(1));
}
}
Exercise 1: Write a program that reads words into two ArrayLists list1 and list2 and then creates a third ArrayList that contains words which are common to both list1 and list2. You may assume that the strings are entered as words separated by a space on a single line and the end is signaled by "-1" (String -1). You can use keyboard.next() to read each word.

A sample dialog is shown below:

Enter words on one line, end with -1 java c pascal ada java c++ -1
Enter words on one line, end with -1 c pascal java lisp lisp -1
[java, c, pascal, ada, java, c++] [c, pascal, java, lisp, lisp] Array List with common strings: [c, pascal, java]

Exercise 2: Write a program that reads words into an ArrayList list1 and creates another ArrayList
list2 that has the same words in list1 but no duplicates. A sample dialog is shown below:
Enter words on one line, end with -1 java c pascal ada java java ada c++ -1

Array List with no duplicates: [java, c, pascal, ada, c++]

Java, Programming

  • Category:- Java
  • Reference No.:- M92397828
  • Price:- $15

Priced at Now at $15, Verified Solution

Have any Question?


Related Questions in Java

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Answer the following question whats the difference public

Answer the following Question : What's the difference public inheritance and private inheritance? What can derived classes inherit from base classes? What cannot be inherited from base classes?

Object-oriented software development1 introduction 11

OBJECT-ORIENTED SOFTWARE DEVELOPMENT 1. Introduction 1.1 Assignment Requirement 1.2 Deliverables and Structure (what to submit) 1.3 Software Restrictions 1.4 How to score high... 1.5 Assumptions 2. System Requirements 2. ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As