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.

learn more… | top users | synonyms (2)

0
votes
2answers
30 views

“Random Quote Of The Day” program

Problem Statement: Create a class diagram and Java code for the following system and scenario, taking into account the possibility of future extensions. "The system is a command line utility ...
3
votes
1answer
40 views

Playing “craps” for the win

No specific question here. I am beginning with Java and here is an exercise. The rules of game: You roll two dice. Each die has six faces, which contain one, two, three, four, five and six ...
3
votes
1answer
26 views

Chess Architecture

I am currently developing a chess game but have made the mistake of putting all my Java code in one .java file. I need help cutting up my code into more manageable chucks. Could someone show me how ...
3
votes
2answers
268 views

Class design for a student class

Problem Statement: Design a STUDENT class to store roll, name, course, admission date and marks in 5 subjects taken from user. Create an array of STUDENT objects. Provide methods ...
1
vote
1answer
21 views

Calculating set difference of lists with or without intermediate variables

Which form of the method do you find more readable? Version with local variables: ...
0
votes
2answers
28 views

Monte Carlo dice [on hold]

For this lab you should re-use your Dice class from the previous week. The user inputs a number n which determines the number of groups of 6 dice to be rolled. The program should output x, ...
3
votes
2answers
67 views

Parenthesis checker

I am working on a parenthesis checker program in Java that reads in a text stream from standard input and uses a stack to determine whether or not its parentheses are properly balanced. For example, ...
1
vote
1answer
37 views

Efficiently packing the header and data in one Byte Array in a single class

I have a header and data which I need to represent in one Byte Array. And I have a particular format for packing the header in a Byte Array and also a different format to pack the data in a Byte ...
3
votes
1answer
45 views

Game State Engine

Can you improve my state engine which consists of the state engine based on an interface and an example menustate? It all works fine but seems a bit cumbersome in terms of the way I have to change ...
0
votes
0answers
12 views

Simple Selectable Menu [duplicate]

The following is my code for creating an adaptable menu, which is invoked by a state engine. It provides the user with a selection of choices, ...
7
votes
4answers
565 views

Guess the random number game

I have created the classic "guess the random number" game: Generator Interface ...
7
votes
5answers
132 views

Counting the number of occurrences of chars in one string, in another string

This program counts the total number of times any character from the source string can be found in the target string. E.g Source String - "Hello World" Target ...
0
votes
0answers
25 views

Java Apache Commons Net SMTP Wrapper Attachment

Can the below code be improved? Are there any major issues with it? Thanks ...
2
votes
1answer
78 views

Permutations of any given numbers

I have solved one programming problem where we have to find all the permutations of given numbers. For example, \$[1,2,3]\$ have the following permutations: $$[1,2,3], [1,3,2], [2,1,3], [2,3,1], ...
-3
votes
0answers
20 views

Support smaller number of frames than pages [on hold]

I've written a FIFO (First-In First-Out) Algorithm function, and I am trying to provide support for smaller number of frames than pages. ...
4
votes
3answers
74 views

Map with different types for values

I am trying to implements a map (that can work as a cache) that has strings as keys and values of different types. In my real case once set the key/values in the map will not change. I used these ...
0
votes
0answers
21 views

Inheritance with one class different [on hold]

I reach a point in my code sometimes, where classes inherit (or implement interface) from a base class, but one child class is different. Consider first my event implementations for Guava's EventBus: ...
0
votes
0answers
18 views

Random result in listview android [on hold]

I want to make a activity and its show a view pager and each page containing a list view with custom data, so i write below codes but when i run my application the result in list view is random , ...
-2
votes
0answers
23 views

How do I print a character multiple times on the same line in Java? [on hold]

I'm given a word and need to print the character 'a' for the length of the word given. This is what I have so far: ...
4
votes
2answers
111 views

Getting the neighbors of a Point in a 2D grid

I am trying to find an algorithm to find all the defined neighbors of a 2D Point (efficiently would be nice, but does not make much of a difference). Here is my ...
0
votes
0answers
19 views

Reverse Nodes in k-Group [on hold]

I am trying to solve a linked list programming question but not been able to clear all test cases. Here is the brief description of problem: Given a linked list, reverse the nodes of a linked ...
6
votes
2answers
257 views

Playing a game throughout the house

Target I wrote this program in a few free hours when I was on an excursion as "youth leader". I had created a game to explore the house, with a 40-field mechanic, using dice for advancing and ...
5
votes
2answers
84 views

Finding the weight of the heaviest path in a binary tree

I'm fairly new to Java, arriving in the "future" from C and returning to type safety from Python. I've programmed an algorithm to return the weight of the heaviest path from the root of a binary tree ...
1
vote
0answers
17 views

Initiliasations for applet

I have the following code in my class and its init() method. It works fine as it is but I'm wondering if there's a better way to do this so that my init() and ...
2
votes
1answer
32 views

Parameterizing a common template [on hold]

I need to execute the same set of statements but with a different name of the field each time. I was wondering if there is a better way to write this? ...
0
votes
1answer
16 views

Facade pattern usage with JDBC-resource on Glassfish

For this project: ...
5
votes
0answers
43 views

Simple micro-benchmarking library

I'm working on a simple micro-benchmarking library in Java. This library makes it easy to benchmark multiple reference implementations. You provide the inputs and trigger the calls, the library takes ...
1
vote
2answers
47 views

Simple interface and class for holding text to be analyzed

I am making a sentiment analysis library targeted first at social media text (like Twitter) and then I will expand it for more general use. For the first step I am making a simple interface and a ...
7
votes
2answers
146 views

Does this simulation follow abstraction and encapsulation?

This below code implements a simulation of an ocean(as 2d-array of cells) which currently have Shark, fish or be Empty. User can run this simulation, as shown below: ...
2
votes
2answers
61 views

Finding a sum of unique triplet that is close to a given number in an array

I asked one question on code review yesterday about my code style, logic and readability of code. Hence, today I kept all those suggestions in mind while solving a new problem question. The question ...
5
votes
1answer
38 views

Parser for simple programming language

I'm writing a basic LL(1) parser in java, but my parser class is quickly getting out of hand and becoming huge. PMD even calls it a "God class" and says that it has "Too many methods." Is there a way ...
1
vote
0answers
32 views

CSMR: Cosine Similarity with MapReduce

I'm working on a project for Large-Scale Text Processing, and the code at the link bellow, is a first implementation of the basic idea of CSMR. CSMR is an algorithm that measures the similarity ...
3
votes
2answers
53 views

Simplifying WebView

I started to code on Android, but I think my code is very heavy and may slow down the performance of my app. For example, when I run my app and I try to drag the page in one of my webviews, it's ...
17
votes
6answers
1k views

Beginner number guessing game in Java

I am a first year CS student. We are currently learning Java and my latest assignment was to create this random number game. I am hoping to get some feedback on code style etc so that I know what not ...
2
votes
2answers
86 views

String compression using repeated character counts

Implement a method to perform basic string compression using the counts of repeated characters. For example, the string aabcccccaaa would become ...
6
votes
5answers
296 views

Finding unique triplets adding up to 0

I am working on a problem "3Sum", in which, given an array S of n integers, are there elements ...
1
vote
2answers
68 views

Finding logic operators [closed]

We get the search string from the UI. Based on the search parameters we need to create a back-end query. This is similar to "Feed Item Query Language(FIQL)". I have wrote the code to find the logical ...
1
vote
3answers
64 views

Use of Exception to log execution stack trace

I've been back and forth with a colleague over the use of Throwable.fillInStackTrace. This Log class is meant to wrap the Simple ...
0
votes
2answers
41 views

Simple print function, passing in various arrays [closed]

I wanted to create a print method that could take in a given array and print it. I can only seem to make the print function specific to my specific array. My print function only can print 1 array, but ...
5
votes
3answers
80 views

Can I simplify my phone look-up program?

I needed to make a phone number look-up program with 10 contacts. I feel like I can shorten the program up a bit, it seems very long, but I don't know how. Any suggestion? Do I need all of the Java ...
5
votes
4answers
452 views

Should I copy list both in constructor and in getter?

I have a simple immutable class: ...
3
votes
2answers
45 views

Correct way of implementing thread safe factory with caching?

I have a ConnectorFactory that creates Connector objects based on parameters like URLs, username and passwords. The ...
2
votes
2answers
107 views

Producer/Consumer Program

I am a semi-new Java programmer that tends to be a perfectionist. What I'd like to know about my code: How it compares to common practice. Is it readable? Are my comments appropriate? Any ...
-3
votes
0answers
42 views

Port-scanning on a website [closed]

I've assembled code in Java to do port scanning on a website and I'd like to have the code reviewed. I got the basic point for the code on Google but I changed it to display the port, its name and it ...
3
votes
0answers
74 views

Dividing a number half into words and half number

Example: If I have a number 1000: I first put commas (In English Standard) that makes it: 1,000 I split the above at the first comma: I get 1 I convert 1 into words: I get One, name it ...
8
votes
4answers
510 views

Text-based BlackJack game

I am a new programmer (I've been doing Java for about 7 weeks) and I am of the type who wants to get it right straight away, so I wonder how this code: Compares to the common practice is structured. ...
4
votes
2answers
67 views

Reflection and Project Euler

I have made a Project Euler runner in order to facilitate the running of the various problems. I have never used reflection before, and I believe that I have found a good use for reflection within ...
3
votes
1answer
35 views

Comparing two implementations of smoosh()

In this question, the suggested solution for smoosh() is as shown below, ...
14
votes
5answers
1k views

Vector (physics) implementation

I recently started learning Java, and I decided to implement a basic vector system for another particle system I was building. ...
-4
votes
0answers
21 views

frequency distribution and histogram [closed]

can someone please write down a sample java program for frequency distribution? also include a java program for a histogram...pls give me a solution asap! if you have a given data for, say, cyclists ...