Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/* * Your expected workflow should be: * Step 1: Eliminate compilation errors. * Declare all the required classes and methods (returning default values if

/* * Your expected workflow should be: * Step 1: Eliminate compilation errors. * Declare all the required classes and methods (returning default values if necessary), * so that the project contains no compilation errors (i.e., no red crosses shown on the Eclipse editor). * Step 2: Pass all unit tests. Add private attributes and complete the method implementations accordingly, * so that executing all tests result in a green bar. * * If necessary, you are free to declare (private or public) helper methods. */

@Test public void test_07() { /* Create an empty repository which can potentially * store up to the specified maximum number (e.g., 3) of items with distinct titles. */ Repository repos = new Repository(3); /* Get all items stored in the repository. */ Item[] items1 = repos.getItems(); /* Get those items stored in the repository, * each of which having its title matching one of those in the input array. * * You can assume that the input array contains no duplicates, and each string * may or may not match the title of some item in the repository. */ String[] titles = {"iPad Pro", "iMac"}; Item[] items2 = repos.getItems(titles); /* Get all items whose amounts are outside the range specified by some upper bound and some lower bound. * You can assume that the two input numbers, the upper and lower bounds, respectively, * are always valid (no error checking is necessary). */ Item[] items3 = repos.getItemsOutsideRange(10, 5); /* All returned arrays are empty as the repository is empty. */ assertEquals(0, items1.length); assertEquals(0, items2.length); assertEquals(0, items3.length); /* For the stored item object whose title matches the input string, if it exists, get its amount. * The returned amount is -1 as such an item object does not exist in the empty repository. */ int amt = repos.getAmount("iPad Pro"); assertEquals(-1, amt); } @Test public void test_08() { Repository repos = new Repository(10); /* If the input item does not exist, * then add it to the end of the repository's stored list. */ Item i1 = new Item("iPad Pro"); i1.increaseAmount(10); repos.addItem(i1); Item i2 = new Item("iMac"); i2.increaseAmount(3); repos.addItem(i2); Item i3 = new Item("Macbook Air"); i3.increaseAmount(12); repos.addItem(i3); Item i4 = new Item("Mac mini"); repos.addItem(i4); i4.increaseAmount(5); /* Now the repository stores 4 items. */ /* Expected to return all stored items in the repository. */ Item[] expected = {i1, i2, i3, i4}; assertArrayEquals(expected, repos.getItems()); } @Test public void test_09() { Repository repos = new Repository(10); /* If the input item does not exist, * then add it to the repository's stored list. */ Item i1 = new Item("iPad Pro"); i1.increaseAmount(10); repos.addItem(i1); Item i2 = new Item("iMac"); i2.increaseAmount(3); repos.addItem(i2); Item i3 = new Item("Macbook Air"); i3.increaseAmount(12); repos.addItem(i3); Item i4 = new Item("Mac mini"); repos.addItem(i4); i4.increaseAmount(5); /* Now the repository stores 4 items. */ String[] titles1 = {"iPad Pro", "Macbook Air"}; /* Expected to return all item objects matching the titles. * * You can assume that the input array contains no duplicates, and each string * may or may not match the title of some item in the repository. */ Item[] expected1 = {i1, i3}; assertArrayEquals(expected1, repos.getItems(titles1)); /* i1's title matches "iPad Pro", i3's title matches "Macbook Air" */ /* Stored at indices 1 and 3 are non-existing items in the repository. */ String[] titles2 = {"iPad Pro", "Blue yeti microphone", "Macbook Air", "iPhone 12"}; Item[] expected2 = {i1, i3}; /* i1's title matches "iPad Pro", i3's title matches "Macbook Air" */ /* Non-existing item titles are ignored. * Only item objects matching existing titles are included in the returned array. */ assertArrayEquals(expected2, repos.getItems(titles2)); } @Test public void test_10() { Repository repos = new Repository(10); /* If the input item does not exist, * then add it to the repository's stored list. */ Item i1 = new Item("iPad Pro"); i1.increaseAmount(10); repos.addItem(i1); Item i2 = new Item("iMac"); i2.increaseAmount(3); repos.addItem(i2); Item i3 = new Item("Macbook Air"); i3.increaseAmount(12); repos.addItem(i3); Item i4 = new Item("Mac mini"); repos.addItem(i4); i4.increaseAmount(5); /* Now the repository stores 4 items. */ /* Expected to return all items whose amounts are * outside the range specified by the upper and lower bounds. * e.g., outside the range with upper bound 10 and lower bound 5 (that is, strictly above 10 or strictly below 5) * (No error checking is necessary. Assume these bounds are always valid.) */ Item[] expected3 = {i2, i3}; assertArrayEquals(expected3, repos.getItemsOutsideRange(10, 5)); } @Test public void test_11() { Repository repos = new Repository(10); /* If the item does not exist, * then add it to the repository's stored list. */ Item i1 = new Item("iPad Pro"); i1.increaseAmount(10); repos.addItem(i1); Item i2 = new Item("iMac"); i2.increaseAmount(3); repos.addItem(i2); Item i3 = new Item("Macbook Air"); i3.increaseAmount(12); repos.addItem(i3); Item i4 = new Item("Mac mini"); repos.addItem(i4); i4.increaseAmount(5); /* Now the repository stores 4 items. */ /* For the item object matching the title, if it exists, return its amount in the repository. * If no items match the title, then return -1. */ assertTrue(10 == repos.getAmount("iPad Pro")); assertTrue(3 == repos.getAmount("iMac")); assertTrue(12 == repos.getAmount("Macbook Air")); assertTrue(5 == repos.getAmount("Mac mini")); assertTrue(-1 == repos.getAmount("Blue yeti microphone")); /* non-existing item */ } @Test public void test_12() { /* Note: the maximum number of items with distinct titles is set to 4. */ Repository repos = new Repository(4); /* If the input item does not exist, * then add it to the repository's stored list. */ Item i1 = new Item("iPad Pro"); i1.increaseAmount(10); repos.addItem(i1); Item i2 = new Item("iMac"); i2.increaseAmount(3); repos.addItem(i2); Item i3 = new Item("Macbook Air"); i3.increaseAmount(12); repos.addItem(i3); Item i4 = new Item("Mac mini"); repos.addItem(i4); i4.increaseAmount(5); /* Now the repository is full. */ Item i5 = new Item("Blue yeti microphone"); repos.addItem(i5); /* do nothing; repository unchanged */ Item[] expected = {i1, i2, i3, i4}; assertArrayEquals(expected, repos.getItems()); }

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

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions

Question

Were members encouraged to participate?

Answered: 1 week ago

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago