Question: To get started, open IntelliJ and create a new java project named asg 6 ( be sure to put it in your ist 2 4
To get started, openIntelliJand create a new java project namedasgbe sure to put it in your istassignmentsdirectory
Part : Project Setup
Your project should adhere to the usual model, view, and controller package structure.
I.e: you should have a root 'edu.psu.ist' package, and within that, an App class housing a main method along with three initially empty subpackages: model, view, and controller.
Part : An 'Orderable' PuzzleBox
Add a class to the model package called PuzzleBox.
The PuzzleBox class should be parameterized by some type T that extends Comparable.
The class should store the following fields:
List items make it an arraylist or linked list choose whichever you conclude will be faster for this asg
Use appropriate access modifiers for the fields. Next, supply a constructor that accepts no parameters and initializes the items list.
PuzzleBox Methods:
The puzzlebox class should offer the following public methods method names marked with a must be implemented recursively None of the methods should be marked static.
Tip: do these one at a time use a Tester class in the model pkg to test them out as you go
addItemsTo takes a List as a parameter, returns nothing, and adds the passed items to this.items.
toString override the toString method such that puzzlebox instances are rendered like so
in a Tester.java main
PuzzleBox box new PuzzleBox;
box.addItemsToListof;
System.out.printlnbox;
beware of your toString leaving trailing whitespace after the last element
clear takes nothing, returns nothing, recursively clears out the internal this.items list.
numOfItems takes nothing, returns an int, and recursively computes the number of items in this.items.
sort sorts the contents of the puzzlebox; this method should mutate this.items list; you can implement any of the following sorting algorithms:
easier implement the following algorithm and in a comment near the method: give the bigO runtime and sentence or two of justification
while this.contents is not sorted:
for each adjacent pair of elements in this.contents:
if the pair is not sortedthen swap its elements.
harder translate Horstmann's arraybased version of mergeSort presented in the sorting chapter of the course text into a java.util.List based version.
Note: you can use Collections.swap method included with java to swap two items in a list read about this online for examples, etc.
inDoubleOrder recursively determines if this.items is sorted in ascending double order; returns a boolean containing true if it is false otherwise.
You should use a helper method for this one that takes a List as a parameter. Some pseudocodeish examples for your tester using the helper method:
box.inDoubleOrder true
box.inDoubleOrder; false
box.inDoubleOrdera a; true
box.inDoubleOrdera b; false
box.inDoubleOrdera; false
box.inDoubleOrder; false
box.inDoubleOrder; true
box.inDoubleOrder; false
box.inDoubleOrder; true
box.inDoubleOrder; false
randomlyPopulate Clears and populates the box with randomly generated items. For this method you'll need the interface described below add it to the model package:
write an interface, IProducer, that is parameterized by some type U and exports a single abstract method: produce with a return type of U
this interface will function as 'generator' of elements of type U; the interface itself should only be implemented as a lambda expression.
Here's the method signature some pseudocode you'll need for the randomlyPopulate method:
public void randomlyPopulateIProducer itemProducer
clear this.items
iterate from upto
T generatedItem itemProducer.produce;
items.addgeneratedItem;
As an example, here's how randomlyPopulate can be called from the main to randomly generate either a smiley or shocked face:
in Tester
PuzzleBox faceBox new PuzzleBox;
faceBox.addItemsToListofcat "dog", "fish";
IProducer faceStrGenerator
Random rand new Random; declare a random num generator
if randnextInt generates a random number between inclusive
return :;
else
return :;
;
clears, then fills the puzzlebox with diff faces
faceBox.randomlyPopulatefaceStrGenerator;
System.out.printlnfaceBox; : : :-) : : :-) : :
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
