MODULE 3 INPUT AND OUTPUT
LAB 3 – Input and Output
Objectives
At the end of this lab, the students are able to
i. To understand on how to illustrate flowchart and write pseudocode.
ii. To write a Java program that capable to obtain input using Scanner class and display the output.
iii. To write a Java program that capable to obtain input using input dialog boxes and display the output
using input dialog box.
3.1 Activity 1
3.1.1 Objective
Writing a Java program using Scanner class and JOptionPane class.
3.1.2 Problem Description
Write a Java program to calculate and display the gross pay for an hourly paid employee based on the
flowchart or pseudocode that you have designed in Lab Module 2 (Activity 1).
i. The program should be able to obtain input using Scanner class.
ii. Modify the program to obtain input and display output using JOptionPane input dialog box
and show message dialog box
[Estimated Time: 30 minutes]
FTKKI, UMT | CSF3034 – PROGRAMMING 1
MODULE 3 INPUT AND OUTPUT
FTKKI, UMT | CSF3034 – PROGRAMMING 2
MODULE 3 INPUT AND OUTPUT
3.2 Activity 2
3.2.1 Objective
Write a Java program based on the flowchart.
3.2.2 Problem Description
Suppose your cell phone calling plan allows you to use 700 minutes per month. If you use more that this limit
in a month, you are charged an overage fee of RM0.35 for each excess minute. Your phone shows you the
number of excess minutes that you have used in the current month, but it does not show you how much your
overage fee currently is. You would like to have a program that be able to enter the number of excess
minutes, and have the program perform the calculation for you. The program should be able to receive input
and display output as shown in the figure below.
*****************************************************
MY CELL PHONE OVERAGE FEE
*****************************************************
ENTER THE NUMBER OF EXCESS MINUTES: 20
OVERAGE FEE = RM 7.0
i. Modify the pseudocode/flowchart as designed in Lab Module 2 (Activity 3) according to the above
problem.
ii. Write a Java program that should be able to obtain input using Scanner class and display the output as
shown in the figure above.
[Estimate 30 minutes]
FTKKI, UMT | CSF3034 – PROGRAMMING 3
MODULE 3 INPUT AND OUTPUT
3.3 Activity 3
3.3.1 Objective
Writing flowchart, pseudocode and Java program.
3.3.2 Problem Description
Write an application that takes Celsius temperature as input and converts it to its Fahrenheit equivalent. The
formula is:
Fahrenheit = (9/5) x Celcius + 32
i. Identify the input-process-output for the above problem.
ii. Design the algorithm in pseudocode and flowchart for the above problem.
iii. Write a Java application using JOptionPane class.
[Estimated Time: 30 minutes]
FTKKI, UMT | CSF3034 – PROGRAMMING 4
MODULE 3 INPUT AND OUTPUT
3.4 Activity 4
3.4.1 Objective
Writing flowchart, pseudocode and Java program.
3.4.2 Problem Description
Suppose you want to deposit a certain amount of money into a savings account, and then leave it alone to
draw interest for the next 10 years. At the end of 10 years, you would like to have RM10,000 in the account.
How much do you need to deposit today to make that happen? You can use the following formula to find
out:
𝐹
𝑃=
(1 + 𝑟)!
where
P is the present amount that you need to deposit today
F is the future value that you want in the account
r is the annual interest rate
n is the number of years that you plan to let the money sit in the account
i. Modify the pseudocode/flowchart as designed in Lab Module 2 (Activity 4) in order to perform the
calculations that can experiment with different values for the terms as depicted in the figure below.
*****************************************************
MY SAVING FORECAST PROGRAM
*****************************************************
WHAT IS THE VALUE YOU WANT TO HAVE IN YOUR ACCOUNT? RM 10000
HOW MANY YEARS YOU WANT THE MONEY TO SIT IN YOUR ACCOUNT? 10
WHAT IS THE ANNUAL INTEREST RATE (IN %)? 3.41
THE AMOUNT YOU NEED TO DEPOSIT TODAY IS RM 7151.129104174272
ii. Write a Java program that should be able to obtain input using Scanner class and display the output as
shown in the figure above.
[Estimated Time: 30 minutes]
FTKKI, UMT | CSF3034 – PROGRAMMING 5
MODULE 3 INPUT AND OUTPUT
3.5 Activity 5
3.5.1 Objective
Writing flowchart, pseudocode and Java program.
3.5.2 Problem Description
Body Mass Index (BMI) is a measure of health on weight. It can be calculated by taking your weight in
kilograms and dividing by the square of your height in meters.
i. Identify the input-process-output for the above problem.
ii. Design the algorithm in pseudocode and flowchart for the above problem.
iii. Write a program that prompts the user to enter a weight and height and display the BMI result using
JOptionPane class.
[Estimated Time: 30 Minutes]
3.6 Activity 6
3.6.1 Objective
Writing flowchart, pseudocode and Java program.
3.6.2 Problem Description
The total price of a product is the price of the product plus the sales tax. Suppose the sales tax is 6%. Write
a program that reads the price of the product and displays the total cost of the product.
i. Identify the input-process-output for the above problem.
ii. Design the algorithm in pseudocode and flowchart for the above problem.
iii. Write a program using JOptionPane class.
[Estimated Time: 30 Minutes]
FTKKI, UMT | CSF3034 – PROGRAMMING 6