0% found this document useful (0 votes)
142 views

Assignment 2

The document provides instructions for an individual programming assignment. It describes two programming problems that require writing Java programs to solve. The first problem involves writing a program to determine if a triangle is a right-angled triangle based on user input of the three sides. The second problem involves writing a program to calculate the call charge for a telecommunications provider based on the call duration and rate category entered by the user. The document provides examples of the expected program output. Students are required to submit the two Java programs in a zip/rar file by the due date.

Uploaded by

Lau JiaMin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
142 views

Assignment 2

The document provides instructions for an individual programming assignment. It describes two programming problems that require writing Java programs to solve. The first problem involves writing a program to determine if a triangle is a right-angled triangle based on user input of the three sides. The second problem involves writing a program to calculate the call charge for a telecommunications provider based on the call duration and rate category entered by the user. The document provides examples of the expected program output. Students are required to submit the two Java programs in a zip/rar file by the due date.

Uploaded by

Lau JiaMin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

STIA1113 PROGRAMMING 1

INDIVIDUAL ASSIGNMENT 2
(Due Tuesday 12 Jan 2021)
Instructions: Answer all TWO (2) questions below by writing a Java program for each of the
questions. You are required to submit an archive file (.rar or .zip) containing all of your Java
programs (Asg21.java & Asg22.java) through the UUMOnline Learning. The name of your
archive file should be STIA1113Asg2.rar or STIA1113Asg2.zip
NOTICE : If you copy someone's source codes, you are cheating and you WILL NOT get any
marks for this assignment

1. A right-angled triangle is a triangle in which one angle is a right angle (90 degrees) and the
largest side is called hypotenuse, c (refer to figure below). If the triangle is a right-angled
triangle, the relationship between the sides of the triangle is as follows:

c = √(a2 + b2) where c is the hypotenuse.

Write a program that can test whether a triangle is right-


angled or not. The program begins by reading from the user
three (double-typed) numbers representing the three sides of
a triangle. The user can enter the three sides in any order and the largest number is
considered as the hypotenuse. Then, the program displays “Yes, this is a right-angled
triangle.” if it is a right-angled triangle or “NO, this is not a right-angled triangle.” otherwise.
Next, the program will ask the user whether to continue with the next set of inputs. If the
user wants to continue, the program will repeat to do the same thing for the next three
numbers. Otherwise, the program will stop reading and it will display the total number of
right-angled triangles that the user have entered.
An example of the program’s running is given below (Note: The bold texts below are
inputs entered by the user)

Enter the three sides of a triangle> 5 3 4


Yes, this is a right-angled triangle.
Do you want to continue? (y/n)> y

Enter the three sides of a triangle> 12 13 5


Yes, this is a right-angled triangle.
Do you want to continue? (y/n)> y

Enter the three sides of a triangle> 92 43 96


No, this is not a right-angled triangle.
Do you want to continue? (y/n)> n

The total number of right-angled triangle = 2

Name of program file to be submitted: Asg21.java

1
2. A telecommunication provider, Maxcom, charges the following rates for telephone calls:

Rate Category Rate per Minute (RM)


1 (Daytime ) 0.07
2 (Evening) 0.12
3 (Off-Peak) 0.05

You are assigned by Maxcom to write a program that can calculate the call charge
made by its customers. The user needs to enter the duration (in minutes) of the call
and the rate category. The program will then display output containing the calculated
charge in 2 decimal places. Then, the program will ask whether the user want to
continue with the next calculation or quit the program. If the user chooses to continue,
the program will repeat again with a new calculation. If the user chooses to stop, the
program will display the total number of customers processed and the total charge
calculated before terminating.

An example of the program’s running is given below (Note: The bold texts below are
inputs entered by the user)

Enter the call duration (in minutes):


40
Enter Rate Category: 1.Daytime 2.Evening 3.Off-Peak
2
The amount you have to pay is = RM4.80
Do you want to continue? 1.Yes 2.No
1

Enter the call duration (in minutes):


30
Enter Rate Category: 1.Daytime 2.Evening 3.Off-Peak
3
The amount you have to pay is = RM1.50
Do you want to continue? 1.Yes 2.No
2

Total customer = 2
Total charge = RM6.30

In writing this program, you must:


- Define and call a method which can calculate and return the call charge
- Perform input validation for the rate category

Name of program file to be submitted: Asg22.java

You might also like