Grading Students

At HackerLand University, a passing grade is any grade 40 points or higher on a 100 point scale. Sam is a professor at the university and likes to round each student’s grade according to the following rules: If the difference between the grade and the next higher multiple of 5 is less than 3, round to the next higher multiple of 5 If the grade is less than 38, don’t bother as it’s still a failing grade Automate the rounding process then round a list of grades and print the results. [Read More]

Stream Merger

Let’s consider the following class: import java.util.Set; import java.util.HashSet; class InputStream { int getStreamId(){ return 0; } } class OutputStream { void emitValue(int value){} } public class StreamMerger { private Set<InputStream> streams; public StreamMerger(Set<InputStream> streams){ this.streams = streams; } public void mergeInto(OutputStream stream){ } public static void main(String[] args){ new StreamMerger(new HashSet<InputStream>()); } } Our goal is to get a collection of streams order it by stream id and then merge those elements into an output stream. [Read More]

Algorithms

This section is about solving simple algorithms, coding challenges, puzzles, katas and dojo material in Java. Sum a Collection Biggest Number Most Popular in the array Common Elements in two Collections Number Counter Characters Counter Birthday Cake Candles String Compressor Sock Merchant Smallest Biggest Electronics Shop Square my List Digital Adder Sum a Collection Given an array of integers, find the sum of its elements. import java.util.List; public class CollectionAdder { public int sum(List<Integer> numbers) { return numbers. [Read More]

Algorithms

Simple Algorithms Fastman Problem Binary Tree Stream Merger Is Pangram Get Month Name Matrix Diagonal Difference Grading Students Apple and Orange Kangaroo GitHub Repository Binary Search Is a search algorithm that finds the position of a target value within a sorted array. BinarySearch.java public class BinarySearch{ int logarithmic(Integer[] data, int key) { int startIndex = 0; int endIndex = data.length - 1; while (startIndex < endIndex) { int midIndex = (endIndex - startIndex / 2) + startIndex; int midValue = data[midIndex]; if (key > midValue) { startIndex = midIndex++; } else if (key < midValue) { endIndex = midIndex - 1; } else { return midIndex; } } return -1; } public static void main(String[] args){ BinarySearch binarySearch = new BinarySearch(); Integer[] myData = {1,2,3,4,5,6,7,8,9,10}; System. [Read More]