Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package adminSite; import static org.junit.jupiter.api.Assertions.*; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import yourPrime.Action;

image text in transcribed

package adminSite;

import static org.junit.jupiter.api.Assertions.*;

import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map;

import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test;

import yourPrime.Action; import yourPrime.Autobiography; import yourPrime.Book; import yourPrime.Comedy; import yourPrime.Drama; import yourPrime.Fantasy; import yourPrime.Movie; import yourPrime.MyMedia; import yourPrime.Pop; import yourPrime.Rap; import yourPrime.Rock; import yourPrime.Song; import yourPrime.Subscriber;

class YourPrimeTest { FuncUtil testFunc; // stream capture to validate output private final ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(); @BeforeEach void setUp() { // dummy songs Song s1 = new Song("Fight The Power", "Public Enemy", 4, new Rap()); Song s2 = new Song("Smell Like Teen Spirit", "Nirvana", 4, new Rock()); Song s3 = new Song("Blinding Lights", "The Weeknd", 2, new Pop()); Song s4 = new Song("We Belong Together", "Mariah Carey", 3, new Pop()); Song s5 = new Song("Hey Jude", "The Beatles", 3, new Rock()); // dummy movies Movie m1 = new Movie("The Godfather", "Marlon Brando, Al Pacino", 175.0, 1972, 4, new Drama()); Movie m2 = new Movie("Avengers: Endgame", "Ironman, Capt. America, Thor", 181.0, 2019, 2, new Action()); Movie m3 = new Movie("Zoolander", "Ben Stiller, Owen Wilson", 90.0, 1998, 1, new Comedy()); Movie m4 = new Movie("The Shawshank Redemption", "Tim Robbins, Morgan Freeman", 142.0, 1994, 5, new Drama()); Movie m5 = new Movie("Forrest Gump", "Tom Hanks", 142.5, 1994, 3, new Comedy()); // dummy books Book b1 = new Book("The Da Vinci Code", "Dan Brown", 2003, 1, 689, new Fantasy()); Book b2 = new Book("Harry Potter and the Deathly Hallows", "J. K. Rowlings", 2007, 3, 607, new Fantasy()); Book b3 = new Book("Show Dog", "Phil Knight", 2016, 5, 399, new Autobiography()); Book b4 = new Book("The Fellowship of the Ring", "J. R. R. Tolkien", 1954, 2, 423, new Fantasy()); Book b5 = new Book("Surely You're Jocking, Mr. Feynman", "Richard P. Feynman", 1985, 5, 356, new Autobiography()); // create subscribers for testing purpose Map> mapLibSong = new HashMap(); mapLibSong.put(0, Arrays.asList(s3, s2, s4)); mapLibSong.put(1, Arrays.asList(s1, s2, s3, s4)); mapLibSong.put(2, Arrays.asList(s2, s3, s4, s5)); mapLibSong.put(3, Arrays.asList(s3, s5)); mapLibSong.put(4, Arrays.asList(s1, s2, s4)); Map> mapLibMovie = new HashMap(); mapLibMovie.put(0, Arrays.asList(m3, m2, m4)); mapLibMovie.put(1, Arrays.asList(m1, m2, m3, m4)); mapLibMovie.put(2, Arrays.asList(m2, m3)); mapLibMovie.put(3, Arrays.asList(m3, m5)); mapLibMovie.put(4, Arrays.asList(m1, m2, m4)); Map> mapLibBook = new HashMap(); mapLibBook.put(0, Arrays.asList(b3, b2, b4)); mapLibBook.put(1, Arrays.asList(b1, b2, b3, b4)); mapLibBook.put(2, Arrays.asList(b2, b4, b5)); mapLibBook.put(3, Arrays.asList(b3, b5)); mapLibBook.put(4, Arrays.asList(b1, b2, b4)); List listUser = Arrays.asList("Arthur Shelby", "Tommy Shelby", "Ada Shelby", "John Shelby", "Finn Shelby"); List listId = Arrays.asList("001", "002", "003", "004", "005"); Map userDb = new HashMap(); MyMedia myMedia; for (int i = 0; i

@Test @DisplayName("Testing for printSubscriber(fee)") void testPrintAllSubscribersByFee() { testFunc.printAllSubscribers("fee"); String testOutput = "John Shelby with outstanding amount = 9.96 " + "Arthur Shelby with outstanding amount = 12.94 " + "Ada Shelby with outstanding amount = 13.94 " + "Finn Shelby with outstanding amount = 16.93 " + "Tommy Shelby with outstanding amount = 19.92"; assertEquals(byteOutput.toString().trim(), testOutput.trim()); System.setOut(System.out); } @Test @DisplayName("Testing for getAverageOutstanding()") void testGetAverageOutstanding() { double val = testFunc.getAverageOutstanding(); assertEquals(val, 14.738); } @Test @DisplayName("Testing for getTotalFeesGroupByMedia()") void testGetTotalFeesGroupByMedia() { Map mapMedia = testFunc.getTotalFeesGroupByMedia(); assertEquals(mapMedia.values().toString(), "[14.9, 39.88, 18.91]"); } @Test @DisplayName("Testing for getCountGroupByMedia()") void testGetCountGroupByMedia() { Map mapMedia = testFunc.getCountGroupByMedia(); assertEquals(mapMedia.values().toString(), "[14, 16, 15]"); } }

Task 02: Quick Fire (5 marks) The media streaming business is very dynamic. Changes occur every second (alright, not every second, but you get the point). Most of the utility methods that you've implemented in Task 01 are essential to for administrative purpose. However, we need to do more, especially in this data oriented business. We need to have some rapid fire methods to pull vital information from our streaming program. There will be loads, but we must be realistic (the task is only worth 5 marks). Therefore, we are going to look at the two most important information to have in-hand, so the management would be happy to get rapid response from us. 1 - You are required to complete the getTotalFeesGroupByMedia () method to provide the current outstanding fees from all subscribers group by the media type, e.g., given the data of all subscriber for that particular month, the method will return the total fees for Movies, for Books, and for Songs. This information can help the management to decide, which media is the most profitable, and they can decide for possible adjustment in the future, i.e., maybe buying more movies for the library (to keep things fluid). Similar to Task 01, you need to use Java 8 Streams, lambda expression and (or) method references to complete this task. There are getters provided in the MyMedia class to help facilitate this operation. Read the comments in the method body for details. The solution is simple, but make sure you cater your solution to the current structure of the program (i.e., check what is available in the codes, and work it out from there) = [3 marks]. 2 - You are required to complete the getCountGroupByMedia () method to return the number of items available inside each subscriber media library, group by the media type, e.g., Given the library of subscriber A as (Movie - 3, Book - 2, Song - 3), and subscriber B as (Movie 2, Book 1, Song 2 ), your method should return (Movie 5, Book 3, Song 5 ) - the total count for each media for all subscribers. This will give the management an opportunity to evaluate the popularity of item in respect to the media type - again, this can be a factor to determine future media offerings (this time based on user consumption). As a good programmer, you should be able to adapt the programming idiom that you've previously applied in getTotalFeesGroupByMedia () method. The logic is essential the same, and you only need to call a different intermediate and terminal operators for your streams. There is no point of re-inventing the wheels (even the marks allocated here reflect that =[2 Marks ]. Notes: Don't overthink the solution - it is not as complex as it sounds, and do check the

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions

Question

2. What role should job descriptions play in training at Apex?

Answered: 1 week ago