1
vote
1answer
64 views

High School Java Class: Pong Project External Reviewer

Panelball class: import java.awt.*; import java.awt.event.KeyEvent; import javax.swing.*; public class Panelball extends JPanel implements Runnable { private static final long ...
1
vote
1answer
50 views

Help creating a workable design?

I received the following feedback for my code: "I still do not see a design here that will work. It is a very bad idea to have the big switch and loop at this point. All you need in your main() ...
0
votes
1answer
43 views

2D Array: Retrieve the “Left” Item

I am creating a game that contains a Board and Pieces. The Board is basically a 2D array of Pieces. [Think smaller chess board] One of the things that I want to accomplish is to be able to retrieve ...
2
votes
2answers
127 views

Calculating and displaying number statistics

I'm writing a program which takes individual int inputs from the user and then outputs some details on the numbers (average, min, max and how many). Input.readInt() is a method I made which simply ...
3
votes
1answer
44 views

Code to find the proper index comparing 3 values for max one

I have an algorithm and the idea is to move over an array choosing as index the index of the neighboring cell that has the max value. I.e. if array[i + 1][j + 1] has the largest value among the 3 ...
2
votes
1answer
191 views

Ranking and sorting on Array/List

My apology, I am quite new to posting a question in this forum. I had a task where I was supposed to write a solution to sort entries(Name, score - in an array/list) in order of score and generate ...
1
vote
0answers
166 views

App engine Java: Sum difference two arrays - How to improve performance?

I have a function in App Engine java where I compare two patterns stored in an int array. Below is the code: public static int patternMatch(int [] pattern1, int [] pattern2, int range) { int ...
0
votes
1answer
63 views

help review array of object code [closed]

public class DoubleMatrix { private double[][] doubMatrix; public DoubleMatrix(int row, int col) { if(row > 0 && col > 0) { makeDoubMatrix(row,col); } ...
1
vote
2answers
63 views

Request for help to tidy up code involving arrays and loops

I posted the following code on here a few days ago: public class Practical4_Assessed { public static void main(String[] args) { Random numberGenerator = new Random(); int[] ...
0
votes
2answers
72 views

add Matrix method review

package homework3; public class DoubleMatrix { private double[][] doubMatrix; public DoubleMatrix() { int row; int col; if(row > 0 && col > 0) ...
4
votes
1answer
162 views

Partitioning Array

Problem: Given a randomly ordered array of n-elements, partition the elements into two subsets such that elements <=x are in one subset and elements > x are in the other subset. one way to do this ...
4
votes
3answers
111 views

Is my code dealing with the presented problem the right way?

I finished this program to print a 2D array, I got the right output, but I'm not sure if I did what was being asked in the problem below. My code to deal with the presented problem: package ...
4
votes
3answers
414 views

A simple array-based Stack class in Java, what are my mistakes?

I have created a simple array-based Stack class with some methods like the actual Stack in Java. I am testing this for mistakes, but since I am learning Java and my tests may not be as comprehensive ...
4
votes
2answers
304 views

A simple ArrayList class in Java, what are my mistakes?

I have created a simple ArrayList with some methods from the actual ArrayList in Java. I am testing this for mistakes, but I am learning Java and my tests maybe are not comprehensive. So I decided to ...
0
votes
1answer
183 views

Am I doing this right? Merging 2 ordered source arrays into one destination array

My instructions were: Add a merge() method to the OrdArray class in the orderedArray.java program (Listing 2.4) so that you can merge two ordered source arrays into an ordered destination ...
4
votes
2answers
2k views

Reading a line from a text file and splitting its contents

I have this kind of file structure MALE:FooBar:32 FEMALE:BarFoo:23 Where I would want to identify the gender and age of person, <Gender>:<Name>:<age> try{ BufferedReader in = ...
4
votes
1answer
968 views

Java 2d array nested loops

Okay, So I have this method I made that searches a 2d array of user input column length and row length comprised of integers. The method is suppose to find 4 alike numbers in rows, columns, and both ...
1
vote
0answers
422 views

Android - get int array from database Cursor

I find this code quite ugly, but in fact, I don't see any finest way to achieve the goal. private static final String TABLE_NAME = "table_name"; private static final String[] allNeededColumns = ...
0
votes
1answer
162 views

Java permutation function returns zero for some reason…? [closed]

The following code works in Python but seems to return zero in Java for some reason. Can you point out any errors? import java.util.ArrayList; import javax.swing.JOptionPane; public class Test { ...
5
votes
2answers
340 views

Find all single elements in an array

I am interested in printing all numbers that do not have a match in an array. Example: 1,3,4,5,3,4,5,5,6 result 1,5,6 Please review my solution bellow. What would be a much better way for this? Any ...
1
vote
1answer
320 views

Java generics, convert nested list to array

I have to interface to some old code using nested arrays, so I have to convert my nested Lists to nested arrays. Any idea, suggestions, improvements are warmly welcomed. public static <E> int ...
10
votes
8answers
12k views

Java function to read a CSV file

I have a java function that reads a csv and returns its content as a Vector<Vector<String>>. The function seems to work as I need it, but my gut feeling says it could be better (never ...
3
votes
3answers
227 views

Missed lab, wondering how this bit of Java code could be improved anyway?

I'm not able to get feedback on this because I forgot about the lab due date, but I'd appreciate some critique anyway. It takes in a user specified number of points then finds the two points with the ...
5
votes
4answers
1k views

Getting the largest element in an array using recursion

Any suggestions on how to make this code more efficient? import java.util.Scanner; public class RecursionLargestInArray { public static void main (String[] args) { int max = -999; ...
4
votes
1answer
246 views

Merging two array of classes

I have this function that should merge two array of classes when id of array1 is equal to id of array2. For simplicity I converted one array into an ArrayList so I can remove the occurrence merged ...
3
votes
2answers
937 views

Optimizing a Deal Or No Deal-style game in Java

could this code be more Efficient? The Game Class import java.util.List; import java.util.Arrays; import java.util.Collections; public class Game { private Case[] cases = new Case[26]; ...
2
votes
1answer
347 views

Can anyone check my code?

Can anyone check this code of mine I want to improve it . give me suggestion or tips and tricks to make this code of mine more efficient Here's my code, I want you guys to give me advices and tips ...
1
vote
2answers
367 views

Matrix bottom left to top right

Can someone please review this simple code for printing all paths in a matrix from bottom left to top right. If element is 1, it is a "wall" and you cannot take it. Possible steps: up and right ...
1
vote
1answer
512 views

An efficient way to shuffle a JSON array in java? (reposted from SO)

This is my first question here so I hope I don't break the protocol too much :) I originally posted this question in SO: ...