0% found this document useful (0 votes)
11 views3 pages

Java Programming Activities Guide

The document outlines a series of programming activities for a tutorial on Java, including calculating BMI, printing natural numbers, calculating factorials, checking for prime numbers, and calculating savings with interest. Each activity specifies the program name, expected output, and deliverables. The final instruction is to submit all Java programs in a zip file to the course submission box.

Uploaded by

ruanzhudie
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Java Programming Activities Guide

The document outlines a series of programming activities for a tutorial on Java, including calculating BMI, printing natural numbers, calculating factorials, checking for prime numbers, and calculating savings with interest. Each activity specifies the program name, expected output, and deliverables. The final instruction is to submit all Java programs in a zip file to the course submission box.

Uploaded by

ruanzhudie
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Programming 1

Tutorial 3
Activity 1
You’ll repeat the BMI activity from a previous tutorial. However, this time, ask the user to enter
his weight (in kilograms) and his height (in meters) via the keyboard, then show his BMI value.
The Body Mass Index can be calculated as follows:
𝑤𝑒𝑖𝑔ℎ𝑡
𝐵𝑀𝐼 =
ℎ𝑒𝑖𝑔ℎ𝑡 2

Additionally, find a way to round the BMI result so that it has no more than 2 decimal places.

Sample program output

Enter your weight (kg): 56


Enter your height (m): 1.63
Your BMI: 21.08 (kg/m2)

Activity 2
Write a program named BasicForLoop which uses a for loop to print out the natural numbers
from 1 to 10.

Expected output

1
2
3
4
5
6
7
8
9
10
Deliverable

[Link]

Activity 3
Write a Java program named FactorialCalculator to calculate factorial of a user-entered
integer using for loop. Factorial is defined as follows:
0! = 1 (factorial of 0 is 1)
n! = n × (n – 1)!
(factorial of n is n times factorial of n – 1)

Sample program output:

What integer you want to calculate factorial for?


11
Factorial of 15 is 39916800

Deliverable
[Link]

Activity 4
Write a Java program named PrimeCheck to find out if a positive integer number (entered by
user) is a prime number.
A number is called prime if it is divisible only by either itself or 1. Number c is divisible by d if c
% d = 0. We say that d is a divisor of c. To make sure that the number c doesn’t have any other
divisor besides 1 and itself, you need to check that c % n ≠ 0 for all n (1 < n < c).

Expected result

Enter a positive integer: 17


It is a prime number.

Enter a positive integer: 15


It is not a prime number.

Deliverable

[Link]
Activity 5
Write a program named SavingsCalculator to calculate your savings account balance after y
years with an interest rate of x percent per year. The interest is re-invested after each year. You
must use a for loop in your program.

Expected result

How much money? 15300


How many years do you want to deposit your money? 10
What's the interest rate (%)? 6.8
After 10 years, you'll receive 29539.55

Deliverable

[Link]

Submission
Submit a zip file containing all Java programs to this tutorial’s submission box in the course
website on FIT Portal.

You might also like