import java.util.ArrayList; import java.util.List; public abstract class AbstractBoxPacking { protected List input; protected int boxSize; public AbstractBoxPacking(List input, int boxSize){ this.input = input; this.boxSize = boxSize; } public abstract int getOutput(); public List deepCopy(List boxes){ ArrayList copy = new ArrayList(); for(int i = 0; i < boxes.size(); i++){ copy.add(boxes.get(i).deepCopy()); } return copy; } }
I need Help fixing the errors in my java code
import java.util.ArrayList; import java.util.List; public abstract class AbstractBoxPacking { protected List input; protected int boxSize; public AbstractBoxPacking(List input, int boxSize) { this.input = input; this.boxSize = boxSize; } public abstract int getOutput(); public List deepCopy(List boxes) { ArrayList copy = new ArrayList(); for (int i = 0; i < boxes.size(); i++) { // this fixes your error. // But to implement deepcopy properly we need Box class that you have as well. copy.add(boxes.get(i)); } return copy; } }
import java.util.ArrayList; import java.util.List; public abstract class AbstractBoxPacking { protected List input; protected int boxSize; public...
What is the output of the following program? import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Test implements Comparable<Test> private String[] cast; public Test( String[] st) cast = st; public int compareTo( Test t) if ( cast.length >t.cast.length ) t return +1; else if cast.length < t.cast.length return -1; else return 0; public static void main( String[] args String[] a"Peter", "Paul", "Mary" String[] b_ { "Мое", ''Larry", "Curly", String [ ] c = { ·Mickey", "Donald" }; "Shemp" }; List<Test>...
/** * */ package groceries; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class ShoppingList { /** * @param args */ public static void main(String[] args) { List groceryList = new ArrayList<>(); groceryList.add("rice"); groceryList.add("chicken"); groceryList.add("cumin"); groceryList.add("tomato"); groceryList.add("cilantro"); groceryList.add("lime juice"); groceryList.add("peppers"); groceryList.remove("cilantro"); for (int i = 0; i if (groceryList.get(i).equals("peppers")) {...
import java.util.List; import java.util.ArrayList; import java.util.LinkedList; public class ListPractice { private static final int[] arr = new int[100000]; public static void main(String[] args) { for(int i=0; i<100000; i++) arr[i] = i; //TODO comment out this line LinkedList<Integer> list = new LinkedList<Integer>(); //TODO uncomment this line //List<Integer> list = new ArrayList<Integer>(); //TODO change the rest of the...
import java.util.ArrayList; import java.util.List; import java.util.Stack; public class Main { public static void main(String[] args) { int programCounter = 0; List<String> program = new ArrayList<String>(); Stack<String> stack = new Stack<String>(); // TODO string probably not best program.add("GOTO start<<1>>"); program.add("LABEL Read"); program.add("LINE -1"); program.add("FUNCTION Read -1 -1"); program.add("READ"); program.add("RETURN "); program.add("LABEL Write"); program.add("LINE -1"); program.add("FUNCTION Write -1 -1"); program.add("FORMAL dummyFormal 0"); program.add("LOAD 0 dummyFormal"); program.add("WRITE"); program.add("RETURN "); program.add("LABEL start<<1>>"); program.add("LINE 1"); program.add("FUNCTION main 1 4"); program.add("LIT 0 i"); program.add("LIT 0 j");...
Adapt the provided program to recreate the following tree: import java.util.ArrayList; import java.util.List; public class TreeNode<T>{ public T data = null; private List<TreeNode> children = new ArrayList<>(); private TreeNode parent = null; public TreeNode() { } public TreeNode(T data) { this.data = data; } public TreeNode<T> addChild(TreeNode child) { child.setParent(this); this.children.add(child); return child; } public TreeNode<T> addChild(T data) { TreeNode<T> newChild = new TreeNode<>(data); newChild.setParent(this); children.add(newChild); return newChild; } public void addChildren(List<TreeNode> children) { for(TreeNode t : children) { t.setParent(this);...
Assessment O Submissions.. l import java.util.List; 2 import java.util.Arraylist; 4 public class ArrayHeapChecker 7Checks if the given array is a representation of a binary tree * @param entries 10 array of entries to be test * ereturn true if the input array encodes a binary tree, false otherwise 12 13 14 public static <K extends Comparable K, vs boolean isBinaryTree(List Entry<k,v entries) ( 15 16 17 // TODO: implement this return true 18 19 2e 21 * Checks if the...
import java.util.ArrayList; import java.util.Set; public class Project { /* * Input is sorted (ascending) to within k positions i.e. each value in the * array is within k positions of where it should be. * For example: * k=1 input=[2, 1, 3, 4, 5] * k=2 input=[3, 2, 1, 4, 5] * k=3 input=[4, 2, 3, 1, 5] * More than one element might be off by k! For example: * k=2...
import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args) { int[] grades = randomIntArr(10); printIntArray("grades", grades); ArrayList<Integer> indexesF_AL = selectIndexes_1(grades); System.out.println(" indexesF_AL: " + indexesF_AL); int[] indexesF_Arr = selectIndexes_2(grades); printIntArray("indexesF_Arr",indexesF_Arr); } public static int[] randomIntArr(int N){ int[] res = new int[N]; Random r = new Random(0); for(int i = 0; i < res.length; i++){ res[i] = r.nextInt(101); // r.nextInt(101) returns an in in range [0, 100] } return res; } public static void...
package cards; import java.util.ArrayList; import java.util.Scanner; public class GamePlay { static int counter = 0; private static int cardNumber[] = {1,2,3,4,5,6,7,8,9,10,11,12,13}; private static char suitName[] = { 'c', 'd', 'h', 's' }; public static void main(String[] args) throws CardException, DeckException, HandException { Scanner kb = new Scanner(System.in); System.out.println("How many Players? "); int numHands = kb.nextInt(); int cards = 0; if (numHands > 0) { cards = 52 / numHands; System.out.println("Each player gets " + cards + " cards\n"); } else...
import java.util.Scanner; import java.util.ArrayList; public class P3A2_BRANDT_4005916 { public static void main(String[] args) { String name; String answer; int correct = 0; int incorrect = 0; Scanner phantom = new Scanner(System.in); System.out.println("Hello, What is your name?"); name = phantom.nextLine(); System.out.println("Welcome " + name + "!\n"); System.out.println("My name is Danielle Brandt. " +"This is a quiz program that...