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.
4
votes
1answer
13 views
Java (Android) abstract class correct implementation
I am looking for some comments on my code and whether or not this is the best way to create an abstract class. In addition, some of the abstract methods are rarely called so I use the base variables ...
9
votes
5answers
159 views
Monty Hall Paradox in Java
I was wondering if this code look neat, and if I should change anything.
I was planning to implement Frames (Or JFrame) tomorrow on it.
Would it be a good idea to use functions?
...
3
votes
4answers
64 views
Custom Sum implementation
There is a custom summary function needed as to receive an integer input (e.g. 32456) and returns 3+2+4+5+6. Can you think of ...
5
votes
1answer
63 views
Formatting an ID string
I'm working with an API which gives me 19-digit ID numbers, formatted in blocks of four except for the last 3 digits. While I tried a for loop, I thought it would be most efficient to simply use a ...
6
votes
0answers
26 views
Simple Java Wizard
Working on a project, I encountered a need to create a wizard and when I ran into the need for a second, slightly different wizard, I generalized into the following:
Top-level Wizard class:
...
5
votes
1answer
45 views
Having sync and async methods by implementing future interface
I need to make a library in which I will have synchronous and asynchronous methods in it and this library will be used by our customer in our company. Some customer will call the ...
4
votes
0answers
37 views
Event Listener and Publisher
This is my first attempt at creating an event system.
My plan is that upon publishing, the listener receives both a reference to the model and to the publisher. This allows the publisher class to ...
7
votes
1answer
81 views
Custom Serialization of Game World
I'm working with libGDX for a game, and over the last few days I have tried a few different types of serialization before settling on a custom serialization implementation. XML had huge file sizes, ...
1
vote
1answer
16 views
Logging errors with the same exception type
I wrote some code which simply retrieves the HTTP status code of the passed in URL. There are multiple potential causes of the same error. I am hoping to get some all around feedback on this code, ...
1
vote
0answers
25 views
Advice on modelling with generics in Java
Use Case
The third party library that I am working with implements its data model in this fashion.
...
1
vote
1answer
66 views
Project Euler 25 - 1000-digit Fibonacci Number
I have recently completed problem 25 from the project Euler site.
The Fibonacci sequence is defined by the recurrence relation:
Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1.
Hence the first 12 ...
1
vote
0answers
8 views
Android: accessing global data through replaceable instance
I have to access global data shared between activities in Android application.
I have simplified DataProvider class to contain only one field - ...
4
votes
2answers
56 views
Find all pairs in an array that sum to a given number
Assume you have an array of random integers and a sum value. Find all
pairs of numbers from the array that sum up to the given sum in O(n)
time. Find all distinct pairs. (1,2) and (2,1) are not ...
5
votes
2answers
444 views
Project Euler 29 - Distinct Powers
I have just completed problem 29 from the Project Euler website:
Consider all integer combinations of \$a^b\$ for \$2 \le a \le 5\$ and \$2 \le b \le 5\$:
\$2^2=4\$, \$2^3=8\$, \$2^4=16\$, ...
9
votes
1answer
141 views
Series, Powers, and Benches
Project Euler problem 48
The series, \$1^1 + 2^2 + 3^3 + ... + 10^{10} = 10405071317\$.
Find the last ten digits of the series, \$1^1 + 2^2 + 3^3 + ... + 1000^{1000}\$.
I made two different ...
3
votes
1answer
45 views
Check input from user
Aim: Read in the userID, check if the userID has 10-digits and check if it not exists in database, when both right, the program will leave the loop.
This code works on my project, but I think its not ...
1
vote
0answers
33 views
Java MVC Main Method and Controller
I'm coding a school project that involves MVC and threading.
This is my Main class. From there I launch the actual client.
...
4
votes
1answer
73 views
Embarking on a Tic Tac Toe journey with JavaFX
On my educational trek through the capabilities of JavaFX, I thought it would be a valuable challenge to create Tic Tac Toe. It took me far longer than expected to get this far, but despite likely ...
5
votes
1answer
68 views
Kth to last element of a singly linked list
Find the kth to last element of a singly linked list
Any comments?
...
-1
votes
0answers
50 views
Java: Program control with OOP thoughts [on hold]
I'm currently developing a console application, where you can add a dataset, edit/delete a dataset and printing a pdf file, with dataset information. I programmed already on C, but not with the OOP ...
3
votes
2answers
68 views
Assembler for Hack Assembly Language - Take 2
I have been reading this great book and I decided to do the Project in Chapter 5: Writing an Assembler for the Hack Assembly Language.
You can find the specification for the Hack Machine Language and ...
15
votes
5answers
786 views
Implement a Shape abstract class
To learn more about OOP, @nhgrif challenged me to implement a Shape abstract class (more details in code remarks below. Here is how I did it. Any and all advice appreciated!
Shape.java
...
2
votes
0answers
37 views
All combinations of a string with special characters
I have written a function which generates combinations of string by replacing 1 or more characters by the symbol "*".
The code is as follows:
...
9
votes
1answer
112 views
The answer to life, the universe, and Project Euler
I've never did a real Project Euler in my life, so I figured it was about to do one.
And what better Project Euler to start with than Problem 42?
Project description from Project Euler:
By ...
3
votes
2answers
324 views
Importing MySQL Database to a .txt File
We just finished working on a Database project in Java Netbeans. We added the feature Import which will import the database record of one user to a text file.
...
-2
votes
0answers
29 views
3
votes
2answers
260 views
Data Persistence
I was wondering if I could get some feedback on the library I created to persist data online.
JitterPushDemo.java
...
9
votes
1answer
211 views
Arranging 8 queens on an 8x8 board
Print all the ways of arranging eight queens on an 8x8 board. Rules:
Queens should not share the same row, column, of any diagonal.
Any comment on my solution?
I didn't write unit tests but I ...
1
vote
2answers
42 views
Edit distance between 2 strings
I have written a program that calculates the "cost" of transforming one string into another. I would like you to review it.
...
5
votes
2answers
97 views
Strategy Game Menus and OOP
Most of my experience is with Objective-C, so I am relatively new to Java inheritance. I understand that there are concepts such as abstract classes and interfaces, but I am still not totally sure ...
1
vote
1answer
53 views
Checking whether one string is a rotation of another
Given a method isSubstring, two strings s1 and s2, check whether s1 is a rotation of s2 using only one call to isSubstring.
Any comments on the code below?
I would like to check the complexities ...
8
votes
1answer
80 views
Java Trie structure
I recently have been working on a Trie in Java. I have looked at the related posts here on Code Review to try and enhance my code, but I do have some methods and constraints not present on other ...
8
votes
2answers
200 views
Finding the Mth to last Element
Challenge:
Write a program which determines the Mth to last element in a list.
Specifications:
The first argument is a path to a file.
The file contains series of space delimited ...
7
votes
2answers
234 views
Implementing a stack and using it to print alternate elements in reverse
Challenge:
Implement a stack interface.
Specifications:
The interface should have ‘push’ and ‘pop’ functions.
Your task is to ‘push’ a series of integers and then ‘pop’ and print every ...
-2
votes
1answer
30 views
Conditionally splitting a string [closed]
My requirement is:
dest = comp ; jump // Either the dest or jump fields may be empty. If
dest is empty, the "=" is omitted; If jump is empty, the ";" is
omitted.
So I may have something like ...
8
votes
2answers
251 views
Decomposing the animal kingdom
I have implemented a Mammal class hierarchy in Java.
Is it an intelligent approach, with respect to decomposition, locality and procedural abstraction?
...
4
votes
2answers
108 views
Verifying value before parsing
I am writing some Java code and am coming across a try/catch block in which I decided to verify the value is not null before parsing it:
...
0
votes
0answers
25 views
Find duplicates in a string [closed]
please review my code. Is there any mistakes or unnecessary loops?
If string has repeated characters then it should to print those repeated characters and its count.
for example:
...
2
votes
3answers
67 views
Sorting movie search results
I want to sort "movie search results" to get most probable movie that match "search".
Input example:
CARS.2.2011.720P.AC3.mkv
I have a NameMatcher class ...
8
votes
2answers
206 views
Unit Tests for a Fraction Class
As my first Java homework, I wrote a class to handle fractions. This Fraction class implements basic operations for the fractions (addition, subtraction, ...
1
vote
0answers
25 views
Simple Java MIDI player followup
This is my second iteration of a simple Java MIDI player. I've made several amendments and would like to see if the code is now correctly implemented and readable. This follows on from the first ...
7
votes
2answers
286 views
The only thing better than being unique
is being first and unique.
Challenge:
Write a program which finds the first non-repeated character in a string.
Specifications:
The first argument is a path to a file.
The file contains ...
5
votes
1answer
119 views
Assembler for Hack Assembly Language
I have been reading this great book and I decided to do the Project in Chapter 5: Writing an Assembler for the Hack Assembly Language.
You can find the specification for the Hack Machine Language and ...
7
votes
1answer
108 views
Lambdas will guide you home, CSS will ignite your code, Java I'll try to FX you
I've been learning JavaFX and wanted to recreate Simple calculator implemented with lambdas. It's also my first time using CSS, whose capability has convinced me of the wonders and appeal of JavaFX ...
1
vote
0answers
24 views
Fragment-changing in Android
My current code is kinda atrocious to switch fragments and everything, but I don't know a better way to check to see if the fragment I'm trying to switch to.
...
0
votes
1answer
75 views
Summation for π [closed]
I was going through my Java book's exercise solutions and comparing and incorporating the author's techniques into my repertoire.
Most of the time, my approach is identical to the author's. When it ...
6
votes
1answer
43 views
Simple Java MIDI player
I created a simple program that allows you to create and play MIDI sounds.
I've used the MVC approach and I’d like to know if there are any improvements to be made regarding the design and structure ...
-1
votes
1answer
53 views
Retrying to read a file [closed]
I have a piece code which retries 3 more times to open a file (see below). Are there potential problems or side effects with the way it is written? How can it be improved? Also, why would one use ...
2
votes
2answers
49 views
Building Data abstraction for line segments using “type abstraction”
Below is the given exercise:
Exercise 5: Segments
Consider the problem of representing line segments in a plane. Each segment is represented as a pair of points: a starting point and an ...
8
votes
4answers
287 views
Creating unique registration numbers using object factories
I'm learning about immutability and uniqueness in Java, particularly the use of defensive programming and object factories.
I have been asked to create a class containing an object factory that when ...