Code Snippets Java

Short texts Java 🧑‍💻 Code snippets Java ✍️ Reading lists Java 👀

A demo code of opening/closing doors

private void handleDoorOpenableState() { // getting the location of world, x 10, y 10, z 10 final Location location = new Location(Bukkit.getWorld(“world”), 10, 10, 10); // getting a block instance of the declared location final Block block = location.getBlock(); // declaring the doorType variable to Material.SPRUCE_DOOR final Material doorType = Material.SPRUCE_DOOR; // checking if block […]

Main.java

BinaryOperator binaryOperator = new BinaryOperator(6, 5); //See: AdditionOperator is assigned to BinaryOperator BinaryOperator operatorAdd = new AdditionOperator(6, 5); //See: SubtractionOperator is assigned to BinaryOperator BinaryOperator operatorSub = new SubtractionOperator(6, 5);

Main.java

BinaryOperator binaryOperator = new BinaryOperator(6, 5); //See: AdditionOperator is assigned to String String operatorAdd = new AdditionOperator(6, 5); //See: SubtractionOperator is assigned to String String operatorSub = new SubtractionOperator(6, 5);

BestSum.java

import java.util.*; public class BestSum { private static List bestSum(long target, long[] numbers) { if (target == 0) { return new ArrayList(); } if (target < 0) { return null; } List shortest = null; for (long num : numbers) { long rem = target - num; List combination = bestSum(rem, numbers); if (combination != […]

Junit test for PointScanner for ComS 228 fall 2021 hw2 Default paths must be updated before running test. Current paths for txt is “src/testFiles/” The PointScannerTest.java should recide in package

package edu.iastate.cs228.hw2; import jdk.nashorn.internal.runtime.regexp.joni.Regex; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import java.io.File; import java.io.FileNotFoundException; import java.util.InputMismatchException; import java.util.LinkedList; import java.util.Random; import java.util.Scanner; import static org.junit.jupiter.api.Assertions.*; class PointScannerTest { private static PointScanner ps; private static Point[] rndPoints; @BeforeAll static void setUpBeforeClass() throws Exception { ps = new PointScanner(“src/testFiles/points.txt”, Algorithm.InsertionSort); //exploiting the pseudo random nature of random […]