I am working on a classes challenge in school. We have to great a Boat class and Harbor class. I have gotten every test to work except the final test of where boats are parked in the Harbor. The Harbor constructor contains an array for the Harbor. The test we have to run is below and the code I have
Tag: arrays
traverse an array in GUI Java
I am doing a questionnaire with questions and written answers. I need that when adding the answer, press the main button, tell me if it is correct or not and show me the other question of the array, until the array is finished. Here I upload the whole code. Answer You have the right idea, but you need to process
Using Streams and StreamSupplier: forEach closes StreamSupplier instead of instance of stream
I am making a obj file loader for an engine that I’m writing and I am trying to use Streams to load vertex index, uvcoord, and normals from this file. The way I intended to do this was to create a new stream from a stream supplier for each type I want to load. Right now I am just trying
Printing results from an array seperately from user input in java
So I’m trying to create a program that takes in the student’s GPA and prints out if they are graduating at an honor’s level, graduating, or not graduating. I have most of the code figured out, but I …
Analysis of recursive approach for rotating an array of integers
While solving Array rotation on LeetCode, I wrote a recursive algorithm to solve the problem: Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,3,4,5,6] rotate 2 steps to the right: [6,7,1,2,3,4,5] rotate 3 steps
Variable inside array not updating its value in Java
I was taking a shot at the FizzBuzz problem and decided to use an array to store the first 15 results in array and then iterate through it. But the variable stored in array is not updating its value if updated later in the loop The variable I does not change its value in the for-loop. It just prints empty
Read a text file to create a 2D Array in Java
I have a text file with first line will be the size of the board and the remaining values will be the values of p row by row. All values are separated by whitespace. For example: 5 2 5 10 3 5 4 6 9 12 3 11 5 9 7 7 7 2 4 8 19 2 6 8
Zipped String from 2 (or more) Strings – “AB” + “YZ” = “AYBZ”
So I am trying to return another String from 2 input sentences zipped together. If the 2 sentences are identical in length it will produce an actual output. If the two input sentences are not identical in length then it will just return an empty string. Here is my code so far but I can’t figure out how to zip
How to auto create arrays
Hello! So there’s a problem. We’re given a file.txt with a lot of numbers (let’s consider the amount is greater than 1000). On the first line we can see the amount of numbers. The next lines contain numbers (1 line = 1 number). So we need to write a code which will autofill arrays with all these numbers. We’re not
How to get object from list with maximum date time object
Below is my code to find the contact object with the latest begin dateTime. DateTime is shown as an object. Is there any method to simplify this code using streams and comparators. Answer I’m assuming that begin is a java.util.Date or any other Comparable? Then you could do: