Question
  1. Open BlueJ and create a new project (Project->New Project...).
  2. Create a new class named ListsDemo.
  3. Open the source code and delete all the boilerplate code.
  4. Type in the code to type (code to type with bigger font) exactly as shown, filling in your name and the date in the places indicated.
    • The code is provided as an image because you should type it in rather than copy-paste. If you need the code as text for accessibility, such as using a screen reader, ask the instructor.
  5. the code to type is
  6. 1 import java.util.ArrayList; * Demo using an ArrayList 5@author (put your name here) 6@version (put the date here) public cl
  7. Compile the code and be sure there are no errors. If there is an error, double-check what you typed compared to the code given.
  8. Create a ListsDemo object and run the method.
    • Compare what you see output to the source code and try to understand what each statement is doing.
    • Review the code statements that don't cause output as well and understand what they are doing.
  9. Take a screenshot to show you completed this part:
    • Open the source code window and put the terminal window showing the output from running it nearby. (Overlapping the windows is okay.)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

/**********************************************ListDemo.java********************************/

import java.util.ArrayList;

/**
* Demo using an ArrayList
*
* @author JUGAL KISHOR SAINI
* @version April,29,2019
*/
public class ListDemo {

   private ArrayList<String> list;

   public ListDemo() {
      
       list = new ArrayList<String>();
   }
  
   public void useList() {
      
       String blueColor = "blue"; //creating a string object
       list.add(blueColor); //add string to array list
       list.add("yellow"); //add String to array list
       /*
       * print the size of list
       * print the first element
       */
       System.out.println("The list has "+list.size()+" elements");
       System.out.println("The first element is "+ list.get(0));
       /*
       * remove the first element of list
       * print removed color from list
       * print number of element in the list
       */
       String removedColor = list.remove(0);
       System.out.println("Removed element "+removedColor);
       System.out.println("Now the list has "+list.size()+" elements");
   }
  
   public static void main(String[] args) {
       /*
       * create object of ListDemo
       */
       ListDemo listDemo = new ListDemo();
       /*
       * use method of ListDemo
       */
       listDemo.useList();
   }
  
}

38 390public static void main(String1 40 41 42 43 main(Stringt] args) f args) create object of ListDemo ListDemo listDemo-new
/**********************************output*************************/

The list has 2 elements
The first element is blue
Removed element blue
Now the list has 1 elements

ConsoleX <terminated> ListDemo [Java Application] C:\Program F The list has 2 elements The first element is blue Removed elem

B Console X D ListDemo.java Χ 1 import java.util.ArrayList; <terminated> ListDemo [Jav The list has 2 elements The first elem

Thanks a lot, Please let me know if you have any problem.........

Add a comment
Know the answer?
Add Answer to:
Open BlueJ and create a new project (Project->New Project...). Create a new class named ListsDemo. Open the source code and delete all the boilerplate code. Type in the code to type (code to type...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a new project in BlueJ and name it LastName-lab8-appstore, e.g., Smith-lab8-appstore. If your App class from Lab 4 is fully functional, copy it into the project. (You can drag a file from File...

    Create a new project in BlueJ and name it LastName-lab8-appstore, e.g., Smith-lab8-appstore. If your App class from Lab 4 is fully functional, copy it into the project. (You can drag a file from File Explorer onto the BlueJ project window.) Otherwise, use the instructor's App class: Create a new class using the "New Class..." button and name it App. Open the App class to edit the source code. Select and delete all the source code so that the file is...

  • C++ Lab 9A Inheritance Employee Class Create a project C2010Lab9a; add a source file Lab9a.cpp to...

    C++ Lab 9A Inheritance Employee Class Create a project C2010Lab9a; add a source file Lab9a.cpp to the project. Copy and paste the code is listed below: Design a class named Employee. The class should keep the following information in member variables: Employee name Employee number Hire date // Specification file for the Employee class #ifndef EMPLOYEE_H #define EMPLOYEE_H #include <string> using namespace std; class Employee { private:        // Declare the Employee name string variable here. // Declare the Employee...

  • In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in...

    In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...

  • A teacher wants to create a list of students in her class. Using the existing Student...

    A teacher wants to create a list of students in her class. Using the existing Student class in this exercise. Create a static ArrayList called classList that adds a student to the classList whenever a new Student is created. In the constructor, you will have to add that Student to the ArrayList. Coding below was given to edit and use public class ClassListTester { public static void main(String[] args) { //You don't need to change anything here, but feel free...

  • PART 1: GETTING STARTED 1. Create a new Java Project. 2. Create a new Tree class...

    PART 1: GETTING STARTED 1. Create a new Java Project. 2. Create a new Tree class and enter this code. You do not have to type in the comments public class Tree { private String name; private int age; private bogJsAn evergreen; // true if evergreen // false if deciduous //CONSTRUCTORS public Tree( { name 0; evergreen = true; age } // you fill this one public Tree (String n, jnt a, bgalean e) //PUT YOUR CODE HERE } //...

  • I was told I need three seperate files for these classes is there anyway to tie...

    I was told I need three seperate files for these classes is there anyway to tie all these programs together into one program after doing that. I'm using netbeans btw. import java.util.ArrayList; import java.util.Scanner; /** * * */ public class MySorts {       public static void main(String[] args) {             Scanner input = new Scanner(System.in);             String sentence;             String again;             do {                   System.out                               .println("Enter a sentence, I will tell you if it is a palindrome: ");...

  • // Client application class and service class Create a NetBeans project named StudentClient following the instructions...

    // Client application class and service class Create a NetBeans project named StudentClient following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. Add a class named Student to the StudentClient project following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. After you have created your NetBeans Project your application class StudentC lient should contain the following executable code: package studentclient; public class...

  • Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src...

    Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src folder, create a package named: edu.ilstu · Import the following files from T:\it168\Labs\lab13. Note that the .txt file must be in the top level of your project, not inside your src folder. o Student.java o StudentList.java o students.txt Carefully examine the Student.java and StudentList.java files. You are going to complete the StudentList class (updating all necessary Javadoc comments), following the instruction in the code....

  • Modify the library program as follows: Create a method in the LibraryMaterial class that accepts a...

    Modify the library program as follows: Create a method in the LibraryMaterial class that accepts a string s as a parameter and returns true if the title of the string is equal to s. Create the same method for your library material copies. Note that it will need to be abstract in the LibraryMaterialCopy class MY CODE **************************************************************** LibraryCard: import java.util.List; import java.util.ArrayList; import java.time.LocalDate; import    java.time.temporal.ChronoUnit; public class LibraryCard {    private String id;    private String cardholderName;   ...

  • How to build Java test class? I am supposed to create both a recipe class, and...

    How to build Java test class? I am supposed to create both a recipe class, and then a class tester to test the recipe class. Below is what I have for the recipe class, but I have no idea what/or how I am supposed to go about creating the test class. Am I supposed to somehow call the recipe class within the test class? if so, how? Thanks in advance! This is my recipe class: package steppingstone5_recipe; /** * *...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT