Tagged Questions
15
votes
1answer
601 views
Blackjack Strategy
I am creating a Blackjack simulator in Java in order to better understand the language. I have written the basic strategy section for a player and it is terribly long.
Is there a better way to do ...
10
votes
1answer
110 views
Good performance when predicting future game states
This question is about my answer to this king-of-the-hill challenge on Code Golf. In short, the purpose of the challenge is to code a slime that, trough various possible moves gains control over an ...
9
votes
5answers
629 views
Using sounds in Java
I'm trying to apply sound today, and the goal in mind was a simple violin tuner. The actionListener seems repetitive/ How might I optimize it (what I tried just ...
7
votes
1answer
75 views
Program to insert, search for and delete an element from an array
I'd like this code to be improved.
...
12
votes
3answers
470 views
Calculating the circumference and area of a circle
This simple program uses Scanner to obtain a radius from the user, then calculates and outputs the circumference and area.
Questions:
Is it customary in Java to ...
12
votes
4answers
153 views
Tic Tac Toe game in Java OOP
I have written a simple GUI Tic Tac Toe Application and since this is my first shot, I think it can be improved a lot.
Please tell me what you think about it and what you see I made wrong so I can ...
1
vote
1answer
69 views
Simple Operations Calculator
I'm practicing Swing effects. Everything works but for some reason I get a ton of error messages in the command prompt when the fields are empty, despite my attempt to add some exception handling ...
7
votes
2answers
60 views
11
votes
2answers
113 views
Dog owner simulator
I've just started programming and read a book called Head First Java.
I thought it would be fun to make a training project that I can put all the stuff I learn into. Is the code I've written here ...
14
votes
3answers
920 views
FizzBuzz implementation using the ternary operator
This is my first time writing JAVA, and I'm trying to start off on the right track.
Using my C++ knowledge, I was able to understand the syntax for the ternary operator, but I'm not sure how it ...
10
votes
5answers
569 views
Yahtzee game (using arrays and object classes)
As part of an assignment for my intro Java class (please bear with my beginner skill set), I'm working on a program for which a Die object class is used to play a Yahtzee game. An overview of the ...
11
votes
4answers
1k views
“Two-pass algorithm” implementation in Java
I'm rather new to Java and to algorithms in general. I implemented the so called Two-pass algorithm, and want to know if there are improvements to my way of implementing it. What it does is it takes a ...
3
votes
3answers
866 views
11
votes
3answers
487 views
Bank card validation module
I hope that someone could review a module I wrote for bank card validation. I included a class that tests some of the methods, this is purely to show the methods work, rather than unit testing. I ...
7
votes
2answers
90 views
Output in one window
Can anyone give me feedback please? I used what I have learnt so far, mainly methods, loops and arrays. I would like you view based on these topics, however, comments on how to improve are welcome.
...
3
votes
1answer
92 views
Parsing version number from a Java source file
I'm extracting the version number from a file like this one. It works, but I find it clumsy and longer than probably needed.
I'd also appreciate some sanity checks as long as they don't make the code ...
5
votes
3answers
213 views
Manipulating Common Fractions
I'm a beginner Java student currently learning from Absolute Java 5th edition. I think I understand the content well but I am never sure of my style. This code is for a question after the second ...
5
votes
1answer
76 views
Downloading a page in Android
I tried to create a class which downloads the html source from a link and saves it. I'm a newbie to all this Android stuff, even new to Java, but this is what I have so far.
It seems to work at ...
5
votes
3answers
280 views
Multiple background tasks
This is taken from my post at Stack Overflow here.
I need your help to review my code for improvement and best practice.
...
6
votes
1answer
123 views
Simple stop watch
I'd like my code to be solid and good. That's why I want someone a little more experienced to give me some feedback so I can improve. Here is the code for a simple stop watch that I created. I feel ...
10
votes
2answers
412 views
Finding average of eight immediate neighbors of a matrix
I have this basic Java code to find average of eight immediate neighbors of a matrix.
Is there any way to simplify or merge any part of it, or can I refactor it?
I'm a beginner in Java programming ...
10
votes
2answers
102 views
“Event Binding” in Java employing Lambda
As I am relativistically new to programming and lack any sort of formal experience in the matter, I was wondering if any of you with a bit more knowledge in the subject would be willing to tell me if ...
14
votes
6answers
1k views
7
votes
3answers
401 views
Alarm clock with “ringing” functionality
I have a question regarding a program that is to run an alarm clock and display the time (HH:MM AM/PM) and also trigger the alarm and display "ringing" at 12:00 AM.
I am a beginner in Java and I am a ...
2
votes
1answer
68 views
Kings Cup drinking game
I'm working on a card game in Java that simulates the drinking game Kings Cup for a school project. I'm having trouble putting the pieces together, and was wondering if someone could tell me what I ...
10
votes
3answers
201 views
Very basic calculator using methods
I have made a basic calculator using methods. This is my first attempt at using methods and would like to see if I can improve on this as there is a lot of repeated code.
...
14
votes
3answers
595 views
Planetary Nomenclature
I'm new when it comes to Java and programming in general, but I feel I have a decent grasp on a lot of the fundamentals.
I've created this "random planet generator" that is virtually useless aside ...
11
votes
5answers
2k views
Logical Sudoku Solver in Java
I've been working on a Sudoku solver as an introduction to the Java programming language. I know there's a bunch of ways to program a Sudoku solver, including a brute force/recursive approach and a ...
14
votes
4answers
1k views
First attempt at a Blackjack game
I am not happy with this code as I am sure there are better ways to do what I'm trying to achieve. I'm a beginner and I've used what I know to date to complete this.
...
8
votes
2answers
103 views
Quadratic Expression Calculator 2
After taking some great advice on this question, I'm hoping for some more feedback on my quadratic expression calculator.
This is my code as stands:
...
12
votes
7answers
659 views
Quadratic expression calculator
I'm hoping to get some feedback on how to improve and optimise a program I wrote which takes three values as input (via the terminal) and uses them in the quadratic formula.
I'm aware this is mostly ...
15
votes
5answers
580 views
Collatz Sequence
I'm a beginner and I only know limited amounts such as if, while, do while. So I'm here to ...
6
votes
2answers
300 views
Pass an array of numbers into a method that's overloaded
I'm doing my homework and it says to write a test program that prompts the user to enter ten double values, invokes this method, and displays the average value.
I was able to get this program working ...
7
votes
5answers
961 views
And the little one said “Roll over”
Below is some code I have written today to test out some bits I have learnt. It isn't much nor is it spectacular. Please critique and let me know what I could/should have done differently or anything ...
6
votes
2answers
237 views
Android Thread and Runnable
This is my code for running a background thread. I believe it is very poor in naming and code structure.
...
4
votes
2answers
69 views
Modularizing an else if statement
Is there any way to take this chunk of an else if and make it its own method? I would need the values of valid and throwLine() to be done in the method containing this if else statement, but I'm ...
6
votes
2answers
346 views
Cleaning up Reverse Polish Notation evaluator
I was wondering if anyone had some general clean up advice on my code. I believe that more helper functions would be my case but I could be wrong. 30 lines maximum per method is my rule. I can't seem ...
15
votes
4answers
765 views
Modelling a Call Center
This is the requirement I have (from the book: Cracking the Coding Interview)
Imagine you have a call center with three levels of employees: fresher, technical lead (TL), and product manager (PM). ...
5
votes
3answers
632 views
Increase performance of removing character from String
I wrote this function as part of interview practice. This method removes a character from a given string.
I was wondering how I could make this code more efficient when it comes to runtime/space. I ...
2
votes
2answers
122 views
Reusing objects using a Generic Object Pool
After reading a lot of documents, I wrote this object pooling code. Can anyone help me to
improve this code.?
I am lagging in validating the object, confirming whether I can reuse it or not?
If ...
7
votes
1answer
126 views
Model simulation using Java annotations
A couple of days ago I posted my code that models systems made up of moving parts. I got several great tips and ideas and here is my latest version. My actions are now methods annotated with @Action ...
9
votes
2answers
889 views
Math expression solver
Recently I've stumbled upon an interesting challenge for me.
You should develop C application, that solves math expressions. Operations such as (+,-,*,/) should be supported, as well as (cos, sin, ...
11
votes
3answers
1k views
Find longest sequence horizontally, vertically or diagonally in Connect Four game
I'm new to programming and also to Java and working on problems in Intro to Java by Robert Sedgewick. Here is my question:
Connect Four: Given an N-by-N grid with each cell either occupied by
...
6
votes
3answers
162 views
Factory for classes unknown at compile time
I have a class called Machine. It contains a list of parts and a list of actions. The list of parts will contain instances of the ...
6
votes
2answers
4k views
Read an input text file and store the tokens in 2 different arrays
I am very new to Java so please ignore if there are obvious mistakes. If my question seems redundant then please guide me towards the correct link. However, I have surfed enough in order to find the ...
7
votes
1answer
592 views
Java Calculator
I tried to make a calculator in Java and have added some stuff. I'm a beginner and have learned yesterday how to make buttons.
...
14
votes
5answers
3k views
5
votes
2answers
2k views
Finding the most common character in a string
I have started to try and work out the TopCoder problems. The "StringDup" problem asks us to:
Create a class called StringDup. Given a string made up of ONLY letters and
digits, determine which ...
11
votes
3answers
6k views
Simple Java calculator
I am a beginner in Java programming. Here is my simple calculator. I hope you could scan through my coding and let me know if there is any error in my coding or how I could simplify the code.
...
7
votes
2answers
134 views
Matching program in Java
I am new to Java and wrote one small program. It works fine, but it looks like it doesn't meet OOP concepts. Could someone look and give me advice so that I can fine tune?
...