Question

MAKING JAVA PROGRAMING: This assignment is very dry to let you focus on using the Containers...

MAKING JAVA PROGRAMING:

This assignment is very dry to let you focus on using the Containers this week since they are pretty weird. Just follow along. There's no "point" or theme. It's just going to use them.

Make a list of ints

Add 3 9 5 2 4 to the list in that order

Loop through the list and output the numbers to the screen

Remove the second item

Loop through and output them again

Make a map of strings to ints

Add five movie titles with the year they were released. One of the movies must be "Bright". It was pretty good.

Output the year Bright was released.

Get rid of all the data from both containers.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.ArrayList;

import java.util.HashMap;

public class Containers {

   public static void main(String[] args) {

       ArrayList<Integer> list = new ArrayList<Integer>();

       list.add(3);

       list.add(9);

       list.add(5);

       list.add(2);

       list.add(4);

       System.out.print("Original list: ");

       for (int i = 0; i < list.size(); ++i)

           System.out.print(list.get(i) + " ");

      

       System.out.println();

      

       list.remove(1);

      

       System.out.print("After removing list: ");

       for (int i = 0; i < list.size(); ++i)

           System.out.print(list.get(i) + " ");

      

       System.out.println();

      

      

       HashMap<String,Integer> map = new HashMap<String, Integer>();

       map.put("Bright", 1999);

       map.put("Titanic", 2001);

       map.put("Red", 1967);

       map.put("Steel", 2013);

       map.put("Transformers", 2005);

       System.out.println(map.get("Bright"));

      

       list.clear();

       map.clear();

   }

}

============================================
See Output

List.adacS); list.add(2); list.add(4); 14 15 16 17 18 19 20 21 System. out.print(Original list: ); for (int i - 0; i < list.sizeO; ++i) System.out.print(list.get(i)+ ); System.out.printlnO; list.remove(1); System. out.print(After removing list: ); 23 24 25 26 27 28 29 30 31 32 for (int i-0; i < list.sizeQ; ++i) System. out.print(list.get(i) + ); System. out.printlnO; HashMap<String, Integer» map = new HashMap<String, Integer>O; map.put(Bright, 1999); map.put(Titanic, 2001); map.put(Red, 1967); map.put(Steel, 2013); map.put(Transformers, 2005); 34 35 36 37 38 39 40 41 42 43 System. out.println(map.get(Bright)); list.clear; map.clear(); Console 3 <terminated> Containers [Java Application] /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/bin/java ( Original list: 3 952 4 After removing list: 3 5 2 4 1999
Thanks, PLEASE UPVOTE

Add a comment
Know the answer?
Add Answer to:
MAKING JAVA PROGRAMING: This assignment is very dry to let you focus on using the Containers...
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
  • This homework problem has me pulling my hair out. We are working with text files in Java using Ne...

    This homework problem has me pulling my hair out. We are working with text files in Java using NetBeans GUI application. We're suppose to make a movie list and be able to pull up movies already in the text file (which I can do) and also be able to add and delete movies to and from the file (which is what I'm having trouble with). I've attached the specifications and the movie list if you need it. Any help would...

  • For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java...

    For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...

  • This project is meant to give you experience writing linked lists and graphs. As such, you...

    This project is meant to give you experience writing linked lists and graphs. As such, you are not permitted to use arrays or any data structure library. You may, however, make use of code presented in class and posted to Blackboard. Objective Your goal for this project is to take a block of text, analyze it, and produce random sentences in the style of the original text. For example, your program, given Wizard of Oz, might produce: how quite lion...

  • ***JAVA: Please make "Thing" movies. Objective In this assignment, you are asked to implement a bag...

    ***JAVA: Please make "Thing" movies. Objective In this assignment, you are asked to implement a bag collection using a linked list and, in order to focus on the linked list implementation details, we will implement the collection to store only one type of object of your choice (i.e., not generic). You can use the object you created for program #2 IMPORTANT: You may not use the LinkedList class from the java library. Instead, you must implement your own linked list...

  • Must be done in C# please! Thanks! In this assignment you will create a program named...

    Must be done in C# please! Thanks! In this assignment you will create a program named Test Scores that displays the average of all tests; average midterm score; average final score; and displays the midterm or final score of a particular student. Create a class level two dimensional integer array named Grades initialized with the following data: 897 242 301 987 116 450 865 128 992 109 88 75 94 70 90 87 81 79 97 79 78 80 92...

  • Purpose This assignment should give you experience in using file descriptors, open(), close(), wr...

    Purpose This assignment should give you experience in using file descriptors, open(), close(), write(), stat() and chmod(), perror(), and command line arguments. Program Write a C++ program that will allow you to add messages to a file that has NO permissions for any user. A Unix system has many files that have sensitive information in them. Permissions help keep these files secure. Some files can be publicly read, but can not be altered by a regular user (ex.: /etc/passwd). Other...

  • This assignment should give you experience in using file descriptors, open(), close(), write(), stat() and chmod(),...

    This assignment should give you experience in using file descriptors, open(), close(), write(), stat() and chmod(), perror(), and command line arguments. Program: Write a C++ program that will allow you to add messages to a file that has NO permissions for any user. A Unix system has many files that have sensitive information in them. Permissions help keep these files secure. Some files can be publicly read, but can not be altered by a regular user (ex.: /etc/passwd). Other files...

  • For Java Program In this lab you will gain experience using all the concepts we learned...

    For Java Program In this lab you will gain experience using all the concepts we learned to this point, which include classes, methods, collections, and file input/output. Also, you will gain experience in team programming. This assignment will be completed by teams of 2. Each member must complete an equal amount of the work in order to receive credit for this assignment. You must write the programmer’s name in a comment for each method you write. You need to create...

  • Java Project In Brief... For this Java project, you will create a Java program for a...

    Java Project In Brief... For this Java project, you will create a Java program for a school. The purpose is to create a report containing one or more classrooms. For each classroom, the report will contain: I need a code that works, runs and the packages are working as well The room number of the classroom. The teacher and the subject assigned to the classroom. A list of students assigned to the classroom including their student id and final grade....

  • Python program This assignment requires you to write a single large program. I have broken it...

    Python program This assignment requires you to write a single large program. I have broken it into two parts below as a suggestion for how to approach writing the code. Please turn in one program file. Sentiment Analysis is a Big Data problem which seeks to determine the general attitude of a writer given some text they have written. For instance, we would like to have a program that could look at the text "The film was a breath of...

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