Sunday, October 7, 2012

Java Exercise #15: Subtraction Quiz

This program is for a first grader to practice subtraction.

Exercise: write a program that randomly two single-digit integers, num1 and num2 where num1 >= num2. It then requests the user to enter the difference

What is 3 - 0? 4
Your answer is wrong.
3 - 0 should be 3
What is 8 - 2? 6
You are correct!

Download Code: Subtraction Quiz

Saturday, October 6, 2012

Java Exercise #14: Leap Year

A year is a leap year if it is divisible by 4 but not by 400 or if it is divisible by 400.

Exercise: write a program that lets the user enter a year and checks whether it is a leap year?

Enter a year: 2008
2008 is a leap year? true
Enter a year: 2002
2008 is a leap year? false

Download Code: Leap Year

Friday, October 5, 2012

Java Exercise #13: Lowercase to Uppercase letter

This exercise is write a program that converts a lowercase letter to uppercase.

Exercise: write a program that converts a lowercase letter to uppercase.

Input a lowercase char: q
Uppercase is Q

Download Code: Lower to Upper

Thursday, October 4, 2012

Java Exercise #12: Sum Digits

This exercise is write a program that sum all digits of an integer.

Exercise: Write a program that reads an integer between 0 and 1000 and adds all the digits in the integer

Enter an integer between 0 and 1000: 932
Sum of digits is: 14

Download Code: Sum Digits

Wednesday, October 3, 2012

Java Exercise #11: Compute Loan (Dialog Box)

This exercise is to calculate the monthly & total payments on the loan where input is taken from and output is displayed on dialog box.

Exercise: Write a program that takes input from user for loan amount, annual interest rate and tenure and display the total and monthly payment on dialog boxes.

Download Code: Compute Loan (Dialog Box)

Tuesday, October 2, 2012

Java Exercise #10: Show Current Time (GMT)

This exercise is write a program that displays current time in GMT

Exercise: Write a program that displays current time in GMT in the format hour:minute:second

Current time in GMT is 23:11:2

Download Code: Current Time

Monday, October 1, 2012

Java Exercise #9: Compute Change

This exercise is write a program that classifies given amount of money into smaller monetary units.

Exercise: Write a program that takes user input as a double value representing total in dollars and cents and outputs a report listing monteary equivalent in dollars, quarters, dimes, nickel and pennies.

Enter an amount in double (Eg: 11.56) : 11.56
 Your amount 11.56 consists of :
 11 dollars
 2 quarters
 0 dimes
 1 nickels
 1 pennies


Caution: One problem with the program is the loss of precision. Running the program for amount of 10.03, 10.03 * 100 to become 1002.9999999999. The program hence will output 10 dollars and 2 pennies. The program will need to re-written to take input in integers (say 1002 for 10.02 for instance).

Download Code: Compute Change