AP Computer Science I s2

AP Computer Science I s2

<p> AP Computer Science TextLab12 Java Assignment</p><p>The "Merging 2 Lists into 1" Program 100 Point Version Only</p><p>Assignment Purpose:</p><p>Students will demonstrate knowledge of algorithms.</p><p>Write a program that will take 2 existing sorted arrays, and merge them together into a single sorted array. The provided file has an Array class. The program has 3 Array objects. Each of the first 2 already contains a sorted ArrayList of integers. These objects are passed to the merge method of the third Array object. This method will merge the 2 ArrayLists together into the ArrayList for this (hint) third object. You essentially need to write the merge method to make this program work. This is not a full-fledged merge sort because you are not sorting a list of random data. You are merely merging 2 sorted lists into 1.</p><p>TextLab11 Student Version Do not copy this file, which is provided.</p><p>// TextLab12st.java // Merging 2 Lists Into 1 // This is the student, starting version of the TextLab12 assignment. import java.util.ArrayList; public class TextLab12st { public static void main(String args[]) { int jsaList1[] = {101, 105, 115, 125, 145, 165, 175, 185, 195, 225, 235, 275, 305, 315, 325, 335, 345, 355, 375, 385}; int jsaList2[] = {110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 270, 280, 320, 350, 400};</p><p>Array list1 = new Array(jsaList1,"List #1"); Array list2 = new Array(jsaList2,"List #2"); Array list3 = new Array("Merged List");</p><p> list3.merge(list1,list2);</p><p> list1.display(); list2.display(); list3.display();</p><p>}</p><p>} class Array { private ArrayList<Integer> list; private int size; private String listName; Exposure Java 2012, APCS Edition Text Lab 12 Page 1 07-09-12 public Array(String ln) { list = new ArrayList<Integer>(); size = 0; listName = ln; }</p><p> public Array(int[] jsArray, String ln) { list = new ArrayList<Integer>(); size = jsArray.length; listName = ln; for (int j = 0; j < size; j++) list.add( new Integer( jsArray[j] )); }</p><p> public void display() { System.out.println("\n" + listName + ":\n"); System.out.println(list + "\n"); }</p><p> public void merge(Array that, Array theOther) {</p><p>}</p><p>}</p><p>100-Point Version Output</p><p>Exposure Java 2012, APCS Edition Text Lab 12 Page 2 07-09-12</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    2 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us