Questions tagged [java]

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 bytecode and run in a virtual machine (JVM) enabling a "write once, run anywhere" (WORA) methodology.

Filter by
Sorted by
Tagged with
7
votes
1answer
108 views

ASCII-Art Generator

Introduction For the purpose of learning how to work with pictures in Java, I created an ASCII-Art Generator. The program can do two things: Convert pictures into ASCII-Art Convert text into ASCII-...
1
vote
0answers
29 views

Routes Between Node, Cracking the coding interview

I am going though Cracking the coding interview and trying to improve my coding interview skills. The question is "Given a directed graph, design an algorithm to find out whether there is a route ...
2
votes
1answer
59 views

Find the number of swaps that has taken place. New Year Chaos. Hackerrank

I am trying to solve the following Hackerrank Problem. I have written the code for the problem. However, it runs for some of the test cases while for others it doesn't. It shows the message : "Your ...
3
votes
2answers
84 views

Which products should be purchased with the given amount of money: Hackerrank?

I am writing code for the challenge given here . Below the text: Each time Sunny and Johnny take a trip to the Ice Cream Parlor, they pool their money to buy ice cream. On any given day, the ...
3
votes
2answers
109 views

Leap year check in Java (functional style)

I have done the leap year check on https://exercism.io already in a lot of languages. Today I came back to the exercise in Java and was playing around with some maybe more funny ways to do the check. ...
1
vote
2answers
67 views

Cut Wood / Facebook Interview

This question was asked through the Facebook interview and the suggested solution is solving via binary search. I have put the binary search solution but it still looks too complicated. Question: ...
2
votes
2answers
60 views

Queue By Using Stack

I have implemented a queue by using a stack data structure. How could I improve it? ...
0
votes
0answers
33 views

Q: Leetcode: Find Pivot Index Java

https://leetcode.com/problems/find-pivot-index/ Question: Given an array of integers nums, write a method that returns the "pivot" index of this array. We define the pivot index as the index ...
1
vote
2answers
120 views

Roman Numeral Conversion in Java

I have designed this by using the stack data structure (similar to balanced parentheses problem) checking if the previous element is decreasing the number or not. ...
1
vote
1answer
70 views

GeekTrust: Tame of Thrones OO

I am trying to solve a problem on GeekTrust, called Tame of Thrones (here) Shan, the gorilla king of the Space kingdom wants to rule all Six Kingdoms in the universe of Southeros. There is ...
4
votes
3answers
418 views

Vowels and consonants in Java-exercises with strings

I feel like my code is too messy-Im looking for possible way to make it more readable/shorter. Goals: 1)Get three strings from user input. They have to be the same length. a)First must contain only ...
0
votes
1answer
62 views

Can you give me pointers on my latest Java program?

Quite new to Stack and I have some Java code I would like you guys to give me pointers on. I've been listening to some programmers and they use terms like good and bad code. I am not really sure what ...
-4
votes
1answer
45 views

It's better simply returning true/false or return the variable? [closed]

In a method I made this ...
3
votes
1answer
91 views

Is it okay to use multiple repositories from inside a single service implementation in Spring?

I currently have two entities, Adress and Company. They both have DTOs to perform CRUD ...
4
votes
1answer
56 views

Finding Build Order For Packages With Dependencies

I gave a shot to infamous finding dependency problem. I highly encourage to give it a go yourself before seeing the solution I came up with. Here is the problem statement: Given a list of ...
1
vote
0answers
30 views

Android single activity app structure for smooth ux

I have an app that has only one activity and 5 fragments. I removed the navigation component because it was buggy and restored the old navigation, which is simply a ...
6
votes
1answer
226 views

Minesweeper with GUI

I created the famous Minesweeper-game in Java, for which I used java-swing to create the GUI. Here's the code: Control.java: This class contains the main-method, ...
0
votes
1answer
59 views

Moving a bot through a maze with Depth First Search

This is supposed to be a depth first search. I just took the idea of what it does and made my own version of it. The bot works it's way through the maze, when it finds a dead end, it moves back to ...
1
vote
0answers
22 views

AIPlaylist: Adaptive media player using VLCJ and Swing

I created a project using VLCJ and a probability function to create a media player that plays your favorite media more often than the others, because I wanted to hear my favorite music and videos more ...
3
votes
0answers
49 views

How to avoid instanceof when working to fill in varying ArrayLists and table models? [closed]

I am looking for a way to improve the following method or to find out if this is the best way to do it. I have a superclass called Product and then I have Yoghurt, Crisp, etc. extending it. My Lists ...
4
votes
1answer
79 views

How to design shopping cart Java application which satisfy modular, extensible and maintainable

I am new in Application Design. I have use-case as below As per the above story I have implemented code as below without any Modularity, Extensible and Maintainable. Could someone share the thoughts ...
2
votes
1answer
97 views

Circular Array - OOP

I have a solution for a circular array. How can I improve this? ...
1
vote
0answers
28 views

Return new thymeleaf page from controller [closed]

0 I have a web app built using Spring boot and thymeleaf. I have used only the index page so far which has different models in it and it work just fine. Now I want to add a new page. By new page I ...
3
votes
3answers
97 views

File System - OOP

I have added an object oriented file system. I am looking for suggestions for how I could improve it further. ...
8
votes
4answers
1k views

Determine if a String has a mirroring head and tail

Problem statement: Given a string, look for a mirror image (backwards) string at both the beginning and end of the given string. In other words, zero or more characters at the very begining of ...
0
votes
0answers
36 views

Generic interchangeable search algorithm applying a search criteria for the object searched

I were considering the possibility of having a util method to implement a generic search algorithm which search procedure could change and adding a search criteria so that the objects passed could be ...
-1
votes
1answer
64 views

Integer pairs with more than 3 common divisors

findPairs produces the Integer pairs so that the numbers from 1 to N and the pair of numbers have a sum less than 50 and have more than 3 common divisors. Could ...
6
votes
1answer
116 views

TicTacToe implementation in Java

Right now I'm studying Java, and as a part of understanding arrays, I've implemented a Tic-Tac-Toe game based on two-dimensional array. Any suggestions/comments are much appreciated! Source code ...
4
votes
2answers
92 views

Quickly throwing together a text-and-button-based client-server web game

With much of the world in lockdown at the moment, my friends and I wanted a way to play our favourite game, Celebrity, over video chat. This seemed like a fun coding project, so I put together a ...
3
votes
2answers
83 views

Unit testing Roman-Arabic-Roman numeric converter

As you can see here, I wrote the methods public static int romanToArabic(String number) and ...
7
votes
3answers
1k views

Practicing OOP with Student and Person

I've just learned the OOP concept of abstraction, and I was wondering if I was implementing it correctly in my code and if you guys can point out any bad practices. test1.java ...
3
votes
1answer
109 views

Roman Numbers in Java

The Problem I wanted to create a program that is able to convert roman numbers to arabic numbers and vice versa. Roman numerals consist of the following symbols: ...
3
votes
1answer
43 views

Storing numbers from a file into a 2-D array

This code will read in double values from a file and store them in a 2-D array. I'm practicing using only arrays (not ArrayLists). The maximum number of lines that will be stored is 10, 10 values max ...
2
votes
2answers
78 views

Rock Paper Scissors in Java (I just want to know whatever feedback you have :) Thank you!)

Any feedback on this code would be greatly appreciated! I am just trying to improve so I can move on to bigger projects. Thank you so much! ...
2
votes
1answer
72 views

Java pagination algorithm

I made a pagination algorithm but in my opinion it is too complicated and it is quite difficult to be understood. This algorithm should show 5 pages where in the middle is the current page. It should ...
3
votes
3answers
96 views

Calculator Object Oriented Design

I am aiming to implement a calculator in an object-oriented way. Here is the solution by using the strategy pattern. Looking forward to some valuable comments. ...
4
votes
1answer
60 views

Reverse String : Recursion

We have to reverse char[] using recursion. Input: ["H","a","n","n","a","h"] Output: ...
5
votes
2answers
99 views

Code to support different measurement systems

I am developing an application in which the user can use different measurement systems. Currently, there is support for the metric and imperial measurement systems. To support these systems, I wrote ...
-2
votes
1answer
50 views

Efficient way to find the greatest result of A mod M in a range of numbers

I am writing a code that takes two numbers N and M and finds the greatest result of A mod M for all the numbers of A in the range 1,2,3,...,N-1,N. 1 ≤ N,M ≤ 10^9 My code is: ...
-2
votes
1answer
22 views

How generate a random pojo value using reactor.core.publisher.Flux and reactor.util.function.Tuples [closed]

Firstly, take in account is my first question here in CodeReview. Any purpose misuderstanding will be highly appreciated if orientaded. Scenario: I want to answer randomly a pojo (json with two ...
0
votes
0answers
37 views

Custom view to select a value

I created a Custom view to select a value. I use horizontal Recyclerview to select an integer value and 2 buttons that decrease or increase the values. Could you consider the code and tell how it can ...
2
votes
1answer
34 views

moving player right or left depending on swipe

In my Player.java class, I want to incorporate a function that moves my player according to the left or right swipes. I also used time in seconds in order to vary the movement in an cyclic way: ...
2
votes
1answer
51 views

String Permutation

Below is my permutation function and I'm looking to make it more elegant and efficient if possible. The function should return a string which includes all the permutations of the given string (...
3
votes
1answer
164 views

Java - parser for html-table

I wrote a program that saves the data from the first table of this wikipedia-article (in german) and then saves the column "Gesamt" (contains daily update of absolute numbers of Covid-19-infected ...
3
votes
1answer
78 views

Building an email generator using abstract factory pattern

I'm trying to build a customer email generator in java using the abstract factory pattern. I understand how to use the factory method pattern; however, I'm a bit confused about the abstract factory ...
4
votes
2answers
220 views

Reader for graph-file with ugly return and questionable use of streams

I wrote a class that contains a static method that reads in files from NetworkRepository and converts them into a list of integer-arrays, each representing an edge. The file format from ...
3
votes
1answer
30 views

I need to know that if everything okay in my BTS put and get method

I implement BinaryTree (K extends Comparable, V) concept to binarySearchTree and I have written get and put method. As far as I check, there is no problem in my code. So now I wonder that are there ...
2
votes
2answers
44 views

Does iterating through a large data set in a Map each time i click impact the performance?

I need to get values from a Map by Adapter position i get from a RecyclerView. As you can see each time i click on an Album Art i create a new array of album objects. ...
0
votes
1answer
51 views

How to Unit Test a Thread which has an infinite loop? [closed]

I wanted to be sure the thread being tested would complete its job by the Assert statement of the unit test, but I couldn't be sure bc of the way I designed the threads. I designed them to run forever ...
2
votes
1answer
48 views

Iterator-Pattern for an iterator that returns one objects that changes

I wrote an algorithm that returns all k-sized subgraphs of another given graph. Because I don't want to make the runtime of the next() call of the iterator depended on k, I don't want to return a new ...