All files needed are in the zipfile

1 answer below »
Answered Same DayNov 18, 2021ITEC 3150

Answer To: All files needed are in the zipfile

Apoorv answered on Nov 21 2021
143 Votes
final-exam-coding-portion-attached-files-nov-17-2020-1113-pm-q4v3rx1b (1)/3150 Final Exam-Coding.docx
3150 Final Exam. Coding Portion
70 points – each question is worth 10 points
Turn in answers to all of the listed questions. If starter files are available, they are listed as part of the question. Coding standards are not graded except for a comment with your name at the top of each file you change.
1. Binary File Input
NEEDED FILES: items.dat
REFERENCE FILE: ObjectFileWrite.java
Create a new program to read items.dat and recreate an ArrayList of MediaItems read from items.dat file. ObjectFileWrite.java shows you how the file was written so you can use the correct input stream library for reading purposes.
Turn in .java file for your code. Name class at your
discretion, but please reference question number or binary file reading in title.
2. Binary File Output
NEEDED FILES: MediaItem.java, BinaryFileWrite.java
Complete the main method in BinaryFileWrite.java to open a file named items2.dat using DataOutputStream. Complete the method so that it writes the contents of the ArrayList named items2. Remember- this needs to be written so that you can read and recreate the MediaItem Objects from the ArrayList.Use appropriate exception handling (try/catch vs throws).
Turn in changed BinaryFileWrite.java. Do not change MediaItem.java. I will be attempting to read items2.dat when grading.
3. Java FX
NEEDED FILES: NONE
Recreate the Java stage shown below using JavaFX libraries.
Turn in your java file or files used to recreate. Name class using question number or Java FX screen. Buttons do not have to change anything.
4. Java FX Event Handling
Recreate the following Java FX GUI and make it so the second stage pops up when the button is pressed on the first stage.
Original Screen:
Pressing button on this stage opens the following stage:
5. Using Sets and HashMaps
NEEDED FILES: MediaItem.java, HashMapFinalQuestion.java
Modify the main method in HashMapFinalQuestion to create a HashMap where Integer is the key and MediaItem is the value. Populate the map with the contents of the mediaItems array using the uniqueID of the MediaItem object as the key.
Then, get a set of the keys, print the set of keys (label it as keys). Next, print each key/value pair as an individual println using an enhanced for loop.
Turn in everything needed to run this program.
6. Binary Search Tree Traversal
NEEDED FILES: IntTree.java, TreeAssignment.java
The given files are similar to the binary in-class assignment file except that it creates a lopsided binary tree rather than a random one. In IntTree.java, complete the method sumOddNodes() so that it recursively sums the total of all the nodes containing odd values. You should probably create a second helper method that does the actual recursion similar to what you did in the binary file lab.
Turn in everything needed to run this program.
7. Multithreading
NEEDED FILES: SharedDataClass.java
Create and launch two different threads. One thread will add together the even elements of theArray in the SharedDataClass and then add the results to the sum in SharedDataClass. The second thread will add together the odd elements of theArray and add that sum to the sum in SharedDataClass. Threads should not be defined or run in the SharedDataClass.
Add appropriate protection in the form of a ReentrantLock to SharedDataClass to make sure no race conditions can occur between the two threads..
In a main method (not in SharedDataClass), launch the two threads, await their completion and print the final sum from the SharedDataClass.
Turn in everything needed to run this program.
final-exam-coding-portion-attached-files-nov-17-2020-1113-pm-q4v3rx1b (1)/BinaryFileWrite.java
final-exam-coding-portion-attached-files-nov-17-2020-1113-pm-q4v3rx1b (1)/BinaryFileWrite.java
//package ssjit;
import java.io.DataOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
/**
 * Complete the main method for the binary file writing question
 * 
 * @author cjohns25
 *
 */
public class BinaryFileWrite
{
    /**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException
    {
        final String outputFile = "items2.dat";
        ArrayList items2 = new ArrayList();

        items2.add(new MediaItem(1, "War and Peace", "book"));
        items2.add(new MediaItem(2, "Star Wars", "movie"));
        items2.add(new MediaItem(3, "Lemonade", "music"));
        items2.add(new MediaItem(4, "Star Wars", "book"));

        // Your code goes here


        try {
 
            //creating data output stram to write the content on binary file .
            DataOutputStream dataOutput = new DataOutputStream(new FileOutputStream(outputFile));
 
            //creating for each loop to traverse items 
            for(MediaItem item : items2)
            {
                dataOutput.writeInt(item.getUniqueID());
                dataOutput.writeUTF(item.getTitle());
                dataOutput.writeUTF(item.getType());
                System.out.println("done");
            }
            dataOutput.close();
        }
        catch (FileNotFoundException e) {
            e.printStackTrace();
        }

    }
}
final-exam-coding-portion-attached-files-nov-17-2020-1113-pm-q4v3rx1b (1)/HashMapFinalQuestion.java
final-exam-coding-portion-attached-files-nov-17-2020-1113-pm-q4v3rx1b (1)/HashMapFinalQuestion.java
//package ssjit;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
 * 
 * Start file for Question 5 on Using Sets and HashMaps
 * @author cjohns25
 *
 */
public class HashMapFinalQuestion
{
    /**
     * @param args
     */
    public static void main(String[] args)
    {
        // some MediaItem objects in an array
        MediaItem[] mediaItems = new MediaItem[4];
        mediaItems[0]= new MediaItem(1, "My favorite Movie", "video");
        mediaItems[1] = new MediaItem(2, "My favorite book", "book");
        mediaItems[2] = new MediaItem(3, "My favorite Movie", "album");
        mediaItems[3] = new MediaItem(4, "My other favorite book", "book");

    System.out.println();
        // create a Hashmap where an Integer is the key and a MediaItem object is the value
        HashMap map = new HashMap<>();

        // place the contents of the array mediaItems in the HashMap using their uniqueID 
        // as the key
        for(int i=0 ; i < mediaItems.length ; i++ )
        {
            map.put(mediaItems[i].getUniqueID(),mediaItems[i]);
        }



        // get a set of the keys
        Set keys = map.keySet();

        // print the set of the keys
        System.out.println(keys);
        Iterator i = keys.iterator();
        while (i.hasNext()) {
           System.out.println(i.next());
        }

        // print each key/value pair in the hashMap individually using an enhanced for loop
        // aka for-each loop.  DO NOT JUST PRINT THE ENTIRE HASHMAP


        for(HashMap.Entry entry : map.entrySet() )
        {
            System.out.println("Key = " + entry.getKey() + 
                    ", Value = " + entry.getValue());
        }
    }
}
final-exam-coding-portion-attached-files-nov-17-2020-1113-pm-q4v3rx1b (1)/IntTree.java
final-exam-coding-portion-attached-files-nov-17-2020-1113-pm-q4v3rx1b...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here