Archive for the ‘Java’ Category

Palindromes

Featured, Java 13.4.2011 1 Comment

A popular problem is how to determine if a String is a Palindrome or not, the following will also assume we are only dealing with Palindromes of single words ie. no spaces or punctuation. The way to determine this is to compare the characters on the left and right ends of the String. If they…

Read More

Money Change Breakdown

Java 28.3.2011 9 Comments
Money Change Breakdown

What is the smallest number of coins (or notes) that are required to give a specified amount of change? This is the next problem we will address. To solve this problem we use basically the same process a shop keeper would when giving change to customers. That is we look for the largest denomination coin/note…

Read More

Pascals Triangle

Java 13.2.2011 14 Comments

Write a Java application that prints the first 10 lines of Pascals Triangle. Each row of a Pascals Triangle can be calculated from the previous row so the core of the solution is a method that calculates a row based on the previous row which is passed as input. Once we have that it is…

Read More

Prime numbers

Java 21.1.2011 No Comments

The assignment here is to calculate all prime numbers less than 100. The solution provided uses the following to determine if a given number is prime. 2 is prime Any number divisible by 2 is not prime If the number is divisible by any odd number then it is not prime Otherwise it is prime…

Read More

Pythagoras Theorem

Java 13.12.2010 No Comments

One of our member students was asked to implement the Pythagoras Theorem using Java. This is a good opportunity to introduce the Math class which contains a collection of static methods for various mathematical functions. We need the square root method (sort) to calculate the hypotenuse, and can also use the pow() method to calculate…

Read More

Fibonnaci Number

Java 3.12.2010 2 Comments

Generating Fibonacci numbers is an assignment often given to Java students when they are being introduced to recursion. Recursion is programming technique that involves a method calling itself to solve a problem. When implementing a recursive solution we look for two things: A base case that returns a value without any subsequent recursive calls. A…

Read More

Calculator Keypad

Java, Swing 14.8.2010 No Comments

This problem involves understanding some of the basics of building a Swing application including how individual components are laid out inside a window, and how your application can react to the user interacting with the application. In this case we need to update a text field whenever a button is pressed. The key points to…

Read More

Simple Mortgage Calculator

Simple Mortgage Calculator

This example expands on the Monthly Payment Calculator example we posted earlier. As well as calculating the monthly payment for a loan, it then goes on to use that to calculate the balance of the loan after each payment. This is often referred to as an amortisation schedule. The displayMonthlyBalance() method handles generating the schedule…

Read More

Monthly Payment Calculator

Java 2.6.2010 1 Comment

This is the simplest form of one of the classic problems given to first year Java students. It aims to get you comfortable with the structure of a simple Java application and how to get input from the user. User input in this example is taken from the console (standard input). The Scanner class comes…

Read More
s2Member®