First Part: (a) Testing Consider a method for finding the unique elements among two lists that are sorted in strictly ascending order. That is, the output list will contain exactly those elements that...

First Part:

(a) Testing Consider a method for finding the unique elements among two lists that are sorted in strictly ascending order. That is, the output list will contain exactly those elements that appear in one of the input lists but not the other. The output list will be sorted in strictly ascending order. Input a does not contain duplicates, and neither does input b.


 static List unique(List a, List b)


Decide 10 independent test cases for the a, b combinations, and in a table, state for each test case (i) what property of the method you are trying to test, (ii) the inputs, and (iii) the expected result or effect. You may write lists using the square bracket notation, e.g., [1, 2, 3]. Try to make your test cases small. Make sure that the “boundary cases” are tested. (b) Recursion Using recursion, write an efficient implementation of the method unique specified in part (a). You may use the List class from Term 2.


(c) Collections You are asked to design and implement a solution for a lecturer for managing team projects for their class. A Student class is already available, which stores, for each student, the ID number, last name and first name. It has a toString method and implements the Comparable interface for comparing students by their last name-first name combination. The class also has a field for storing the team name for each student, which is a string unique to the team.


You need to define a class Teams in which the information pertaining to each team can be stored. It should store at a minimum the students who are members of the team. It should be extensible so that, in future, other information can be added such as the team supervisor, meeting schedules, marks etc. Frequent operations include updating information about individual teams, and tabulating all teams in an alphabetical order. Describe what data structure you would use to store the teams and discuss its efficiency considerations.


Define the Teams class along with • a constructor that takes an array of Student objects. • methods to add and delete students. • a print method that prints all the teams along with their members in the format team : member 1, member 2, . . .


where the teams as well as members appear in sorted order. Second part: (a) Computation (conditionals, loops, arrays, exceptions) Assume that we need for testing purposes n randomly generated values of type double in the range between a and b. Write a corresponding method


           public static double[] generateTestValues(int n, double a, double b).


If a is greater than b or n is negative your method should throw an IllegalArgumentException. Demonstrate that the code works with four well chosen examples in a main method.


(b) Classes, Sub-classes An online shop sells items. Each item has a price and a name. Items are either DVDs or books, for a DVD the playingTime is given in addition, for a book the numberOfPages. Furthermore any item may be discounted by a discountPercentage between 0 (included) and 100 (excluded). Represent the situation by a suitable class structure. Each class should contain a suitable constructor and a toString method that presents the information in a suitable human readable form. Make use of inheritance where appropriate. Give suitable examples for the different possibilities of items (DVD versus book, and some items discounted versus some not) in main methods. Important: Justify your design decisions (as Java comments).


(c) Graphics, Graphical User Interfaces Two values in a fixed range (such as temperature between -10 and 40, and air pressure between 0.87 hPa and 1.09 hPA, or volume-left and volume-right for two loudspeakers) are to be displayed by two indicators as shown in Figure 1 below. You can assume that the values are already converted to angles between 0 and 90 degrees.


Using only the Line and Polyline classes write a JavaFX program to produce the corresponding display. Note that angles between 0 and 90 may need to be appropriately converted to angles between 0 and Math.PI/2. Note furthermore that a circle segment can be represented by a function x -> Math.sqrt(1-x*x). You may wish to use for your answer the FunctionGraph.java example of week 8 in Term 1 (see wk08.zip ) Your answer must be general and work for any two angles between 0 and 90 degrees.


May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here