Tagged Questions
Java (not to be confused with JavaScript) is a class-based, object-oriented, strongly typed, reflective language and run-time environment (JRE). Java programs are compiled to byte-code and run in a virtual machine (JVM) enabling a "write once, run anywhere" (WORA) methodology.
1
vote
0answers
7 views
File reader and streamer component running in its own thread on Android
In an Android project,
I have a class whose job is to read lines from a file,
and then pump those lines to a message handling thread,
looping forever until told to stop.
The main operation of this ...
3
votes
1answer
62 views
Optimizing code to find maximum XOR in Java
This problem is from HackerRank (not a competition, just for practice)
Basically what you do is take in two integers as a range and then finding the maximum XOR from a pair of integers in that ...
1
vote
1answer
30 views
Party Invitation - Trimming the Invitation List
I am learning Java right now and am coding some simple programs to practice. Right now, one of my for loops has an inelegant way of ending the loop. I was wondering ...
4
votes
1answer
129 views
Listing the first 100 prime numbers
I thought of this implementation, and I want to get feedback from you.. what design would you use for printing first 100 prime numbers?
I used the fact that, if the number is not divisible by any ...
2
votes
1answer
37 views
Find the smallest number of square numbers to create n
An interview question I got -
Given int n, find the smallest number of square numbers that fit inside n.
Example:
...
3
votes
2answers
92 views
Solving a practical problem involving square of root of a number
A student has a book containing 411 pages.
She read a certain number of pages on the first day and created a rule to work out how many pages she had to read on each succeeding day.
She decided ...
2
votes
2answers
34 views
Sort ArrayList in a better way
I have a list of categories (in this example I used String but in my project I have a model) which must be sorted like this:
on top we should have 2 categories ...
6
votes
3answers
184 views
Is the way I'm handling deck (card) generation the wisest way to do it?
My Deck Class:
(In case it isn't clear, a Card is just an object with two enums, one for suit and one for value).
I'm ...
1
vote
0answers
10 views
Commute info entry fragment for Android app
This is a simple app for taking down a user's home and work address, the days of their commute, and the times they go to work and go home. The times and workweek are entered via TimePicker dialogs ...
-1
votes
0answers
15 views
Overriding FilterRead read() method in java [on hold]
I am trying to override the read method of FilterReader in java. My goal is to substitute one run of characters for another. I have accomplished this, but the code fails to stop and eventually the jvm ...
2
votes
2answers
33 views
Generating a 64 bit unique integer in Java
I need to generate a 64 bit unique integer in Java. I need to make sure that there is very few or no collisions if possible.
I came up with the below code which works fine:
...
5
votes
3answers
54 views
Design of a remoteControl class for connecting to electronic devices
In a course that I'm taking on learning object oriented programming in java, I have completed an assignment for modeling a home entertainment system and the ability for a user to be able to use a ...
1
vote
1answer
12 views
Location information (store/send over network)
I have to calculate a user's location periodically and store & send it over the network on Android. I also have to indicate errors during calculation of location as well. The errors could come ...
2
votes
1answer
30 views
Shortening JPA criteria query boilerplate
I've used hibernate for a long time. Recently I started using JPA, but I can't find a short way to write a simple select in less than these seven lines (the use of criteria is a must in this project).
...
6
votes
4answers
487 views
Basic playing card generation and shuffle
This is my first attempt at Java so I appreciate any criticism or pointers. The program should generate a full set of given decks and then shuffle them.
...
2
votes
2answers
42 views
How many chores can you accomplish in a set time?
I am learning java and doing some practice problems. My code works, but I feel like I used a workaround sort of way to accomplish it. Is there another way to express what I want the program to do?
...
2
votes
2answers
113 views
2
votes
2answers
27 views
Premium palindromic primes
Challenge: Write a program which determines the largest prime palindrome less than 1000.
The answer is 929, and my program correctly finds and prints this, but actually ended up being more complex ...
5
votes
4answers
250 views
Federal and state income tax calculator
I'm trying to optimize this code by:
condensing repetitive statements
Improving the code/make it less confusing
Branch out to include other filing status such as "married" "joint" filing status
...
2
votes
2answers
24 views
Determining if there is a route between two nodes in a directed graph
This algorithm should return a boolean value, telling if there is a path between two nodes in a given directed graph.
...
-2
votes
0answers
17 views
how to parse this URL using JSOUP [on hold]
I would like to parse this URL and take just brand names using JSOUP. please help me. This is a little tricky to get only brands. so please have a look
...
0
votes
0answers
60 views
Android app with an ActionBar, a ViewPager and an AsyncTask
I'm new at Android and Java development and I've put together a demo app to start learning, which is made of:
a main activity extending ActionBarActivity, in ...
5
votes
1answer
66 views
Paint fill function
Implement the "paint fill" function of image editing programs: Given a
screen point and new color fill the surrounding area.
Any comments on the code below?
Time complexity: ...
3
votes
2answers
65 views
Giving multiple choices that lead to different scenarios
I'm doing a Java text based game as a course project.
Everything is fine but the part where it shows a conversation, then gives you 2-4 options, then each actions will lead to different text and ...
0
votes
0answers
18 views
Giving multiple choices that lead to different scenarios (Java text based game) [duplicate]
I'm doing a java text based game as a course project.
Everything is fine but the part where it shows a conversation, then gives you 2-4 options, then each actions will lead to different text and ...
3
votes
1answer
27 views
Java CharSequence iteration
A project I am working on requires me to check the first character of an input string, to determine if it is a numeric character. I have developed the following code:
...
1
vote
2answers
58 views
Jolly jumper sequence
Another challenge from CodeEval that's causing me great pain...
Trying to find out if a sequence if a Jolly Jumper, which is
A sequence of n > 0 integers is called a jolly jumper if the absolute ...
1
vote
2answers
83 views
Tic Tac Toe getWinner() method logic for a grid of any size nxn
I have a college assignment in which I have to make a Tic Tac Toe game work. Some of the code has been provided by my instructor like method signatures etc. Now the rules for this particular project ...
0
votes
1answer
33 views
Permutations of a string
I wrote the following code to permute the characters of a string assuming there is no repeated character.
I also want to make sure the space complexity of this algorithm is \$O(n*n!)\$: There are ...
7
votes
3answers
232 views
Rocks, Paper Scissors game
I wrote a Rock Paper Scissors game and was hoping to get some feedback on issues like:
Am I utilizing object oriented techniques correctly? What can I do better?
Am I using ...
3
votes
2answers
300 views
QuickSort for a List<T>
I want my QuickSort class to have a static sort method that sort any List for any object that extends Comparable. Have I coded my class correctly? Can I make the use of generics a bit cleaner or is ...
2
votes
1answer
39 views
Improving time complexity of cheapest travel route algorithm
Below is the code to find the cheapest route for a passenger. stationsUnexplored is a Queue to which stations are added and ...
2
votes
2answers
153 views
Is there some way of taking advantage of code reuse in this example?
I am implementing a set, using an array as the backend.
Here is how I declared it (and some method implementations):
...
0
votes
0answers
20 views
Removing an element from a set of integers [on hold]
I am implementing an set, using an array as the backend.
Here is how i declared it
...
1
vote
0answers
24 views
Approximately putting integers into buckets such that the sum of bucket differences is minimized
I have the need for load balancing in my MSD-radix sort routine and doing it optimally is not an option. So I tried to play with two simple routines for putting integers into a prespecified amount of ...
7
votes
1answer
488 views
An Army of Ones
I've been practicing using recursion lately and thought this was a case where it would prove really useful, is this good use or is there some superior non-recursive way to go about it?
Challenge:
...
4
votes
2answers
891 views
Switch statements in Rock-Paper-Scissors game
I am very much new to design pattern. I'm trying to modify the Rock, paper, scissor game from an example book where I try to add more various design pattern. But I am encountering two similar switch ...
1
vote
2answers
62 views
4
votes
2answers
134 views
2048 Java clone
I'm making a 2048 clone and my method to move and merge tiles is really long. I've heard of helper methods but I'm a little lost as to how I should use them. I feel like my code is a little too long ...
30
votes
2answers
2k views
You are being watched! - Comments of Interest
You are being watched
Code Review has an open system
A machine that spies on you on every hour of every day
I know because I built it.
I designed the machine to detect suggestions to post ...
3
votes
1answer
34 views
Parsing a long without using inbuilt function parseLong
I came across it as a problem to solve. What kind of limitations are there?
...
4
votes
4answers
357 views
Digital root recursive function
Haven't any experience writing recursive functions.(Generally tend to avoid them - not sure if that's a negative). What do you think about the following?
This is also my first time using JUnit, I'd ...
1
vote
0answers
43 views
Shopping cart application in Spring MVC
I am creating a shopping cart application to learn Spring MVC. I want to display a list of all categories and subcategories in more than one page. i.e; Home Page, Products page, Category page.
In the ...
1
vote
0answers
20 views
Bidirectional Edmonds-Karp algorithm in Java
The Edmonds-Karp algorithm relies on breadth-first search in order to find an augmenting path in the residual flow network. This version of the algorithm uses bidirectional breadth-first search in ...
1
vote
1answer
31 views
Removing getters for a custom enum [closed]
Recently, I perform re-factor on one of my frequent used custom enum, by removing its getter.
My rational for doing so it.
The enum's custom fields are immutable
Only use getters when it is ...
3
votes
3answers
55 views
Exponentiation in logarithmic time
Input: Real number y and Integer number x
Output: x^y
Constraint: Must be done in O(log(y)) time.
Notice that O(log(y)) is O(length-of(y)).
...
4
votes
3answers
190 views
Partition a list of numbers into even and uneven numbers
Input: An array of integers.
Output: That same array, but with the even numbers at the front and the uneven numbers at the back of the array.
I wrote three different solutions, depending on the ...
1
vote
1answer
20 views
Counting how many LCD segments are needed to display a number [closed]
I made a program which reads digits of series of numbers and then tells you which would need the largest number of "lines" to be written with a classic digital calculator (example: for 1 you need two ...
3
votes
0answers
30 views
Edmonds-Karp algorithm for maximum flow in Java
I have this implementation of Edmonds-Karp algorithm for finding maximum flow in networks. It runs in \$\mathcal{O}(VE^2)\$ time.
What do you think?
AbstractMaximumFlowFinder.java:
...
-1
votes
1answer
39 views
Business interfaces and packages
When I last did a lot of Java programming, I'd do this:
All classes in a package would be default (package) visibility.
Each package would have a public PackageNamePack factory class, e.g. ...