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

Programming Exercises for ITCS111

This document contains 15 programming problems involving calculations related to distances, areas, points systems, currency conversion, employee pay, ticket sales, averages, and salaries. The problems require writing Java programs to read input values, perform the necessary calculations, and output the results. Common calculations include converting between units, computing averages, applying percentages, and formatting monetary values.

Uploaded by

Maryam Kamashki
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)
36 views3 pages

Programming Exercises for ITCS111

This document contains 15 programming problems involving calculations related to distances, areas, points systems, currency conversion, employee pay, ticket sales, averages, and salaries. The problems require writing Java programs to read input values, perform the necessary calculations, and output the results. Common calculations include converting between units, computing averages, applying percentages, and formatting monetary values.

Uploaded by

Maryam Kamashki
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

Dr.

Ali Alsaffar 1

University of Bahrain
College of Information Technology
Department of Computer Science
ITCS111/ITCS113
Introduction to Computer Programming

1 Basic Problems
1. Write a program that converts a distance measure from inches to cents. Note that one inch is equal to 2.54
centimeters?
2. The area of a triangle is computed by taking half the product of its base and height.
1
Area =× base × height
2
Write a program that reads the base and height of a triangle and displays the area.
3. Students are awarded points toward their grades based upon the addition of the average of three quizzes
(Q1 , Q2 , Q3 ), the midterm exam (M T ), and the final exam (F IN AL). Quizzes are marked out of 5, the midterm
is out of 30, and the final is out of 70. Compute the total points using a Java program and print the result out
of 100 according to the following percentages: Quizzes: 25%, Midterm: 35%, and Final: 40%.
4. Write a program that reads a student name followed by his/her id. The program should then display on screen
the student’s name followed by his/her academic year. For example, the academic year for the id 20102323 is
2010.
5. Write a program that reads three floating point numbers N1 , N2 , and N3 from the user. It is required to find
and print the value of the following formula:
N1 × N2
F = N1 + − N3
4
6. One large chemical company pays its salespeople on a commission basis. The salespeople receive BD. 75/600
per week plus 9% of their gross sales for that week. For example, a salesperson who sells BD. 1890/— worth
of chemicals in a week receives BD. 75/600 plus 9% of 1890/—, or a total of 75/600 + 170/100 = 245/700.
Develop a program that will input each salesperson’s gross sales for last week and will calculate and display that
salesperson’s earnings?
7. Write a program that reads two currency codes, exchange rate from first currency to second and the amount of
money to be converted. Your program should display the converted amount for each currency using the following
equations:
First Currency Amount = Currency Amount × Exchange Rate
Second Currency Amount = Currency Amount / Exchange Rate
Format the output to 4 decimal places.

Sample Input/Output
Enter currency codes: USD BD
Enter Exchange rate: 0.3774
Enter the amount: 125.0
USD 125.0000 = BD 47.1750
BD 125.0000 = USD 331.2136

8. Write a Java program that will perform some calculations regarding a cyclist coasting on a road. The program
will ask the user to enter the cyclist’s initial speed Vinitial , the duration (in minutes), and the final speed Vfinal .
The program will then calculate the rate of acceleration using the formula:
acceleration = (Vfinal − Vinitial ) ÷ duration
Next, calculate how long it will take for the cyclist to stop (given the initial speed and the calculated acceleration.)
The necessary formula is:
time = Vinitial ÷ acceleration
Display the acceleration and time on screen formatted to the below samples.
Dr. Ali Alsaffar 2

Sample Input/Output
Enter initial speed, final speed and duration
18.0 36.0 4.0

Acceleration = 4.5
4.0 minutes to stop

9. Write a program that reads from the keyboard the following input:
• Person Full Name written in a single line.
• Person CPR number (9-Digits) written in the next.

Your program should find and print on screen the birth year of this person. The birth year can be extracted
from the first two digits of the CPR. Assume all persons were born before the year 2000 and after the year 1910.

Sample Input/Output
Enter your name: Jassim Ali Ahmed
Enter your CPR: 740707573
Jassim Ali Ahmed was born in year 1974

10. The curriculum of any bachelor degree program consists of credit points which must be completed by all students
enrolled in the program. Write a program that will ask the user to enter his/her name, program credit, and
expected credits to be completed yearly. The program will then calculate degree duration in years. The duration
in years is calculated by:

Degree duration in years = program credits ÷ expected credits to be completed yearly

The program will display the student name, degree duration in years, and expected graduation year formatted
similar to the below sample output. Expected graduation year equals the year 2015 plus degree duration.

Sample Input/Output
Enter your name, program credits and expected credits:
Ali 130 30
Name: Ali
Degree duration: 4 years
Expected graduation year: 2019

11. Write a program that calculates and prints the monthly paycheck for an employee. The net pay is calculated
after the following deductions:

• Medicare/Medicaid Tax: 2.75%


• Pension Plan: 6%
• Health Insurance: BD. 75
Your program should prompt the user to enter the gross amount and print the net pay. A sample Input/Output
is shown below:

Enter gross amount (BD): 650

---------- Paycheck -----------


Gross amount: 650.000
Medicare/Medicaid Tax: 17.875
Pension Plan: 39.000
Health Insurance: 75.000
-------------------------------
Net Pay: 518.125
Dr. Ali Alsaffar 3

12. Write a program that reads from the keyboard two integers representing hours and minutes. The program should
convert the time (hours and minutes) to seconds. Your program should write the result on screen as shown in
the sample I/O below. the sample below:

Sample Input/Output
Hours? 10
Minutes? 15
Time in Seconds = 36900

13. The manager of a football stadium wants you to write a program that calculates the total ticket sales for a game.
There are four types of tickets – Box, Sideline, Premium, and general Admission. Data is stored as shown below:

250 5750
100 28000
50 35750
25 18750

The first line indicates the ticket price is $250 and that 5750 tickets were sold at that price. Output the number
of tickets sold and the total sale amount. Format your output with two decimal places.

14. Write a program that reads three salaries from the keyboard and displays their average on screen formatted with
3 decimal places as shown below in the sample I/O.

Sample Input/Output:
Salary1 ...........456.400
Salary2 ..........1230.520
Salary3 ...........650.550
Average ...........779.157

15. Two employees in a company are up for special pay increase. Write a program that reads the last name, first
name, current salary and percent pay increase for both employees. Your program should display their salaries
after the increase.

Common questions

Powered by AI

The program extracts the birth year from the first two digits of the CPR number. It assumes that all persons were born between the years 1910 and 1999. Consequently, the extracted two-digit prefix (e.g., '74' in CPR number '740707573') is prefixed with '19' to obtain the complete birth year ('1974').

The program first reads two currency codes, an exchange rate from the first currency to the second, and the amount of money to be converted. It then calculates the equivalent value in both currencies using the formulas: First Currency Amount = Currency Amount × Exchange Rate and Second Currency Amount = Currency Amount / Exchange Rate. The result is formatted to four decimal places .

Ticket sales and total revenue are computed by multiplying the number of tickets sold at each price category by the price of each ticket. For example, a line indicating '250 5750' means 5750 tickets were sold at $250 each. The program aggregates these computations for all ticket types (Box, Sideline, Premium, general Admission) to determine the total sales revenue, outputted with two decimal places .

To calculate how long it takes for a cyclist to stop, the program needs the cyclist's initial speed (Vinitial), the final speed (Vfinal), and the duration of coasting in minutes. The rate of acceleration is calculated using the formula: acceleration = (Vfinal - Vinitial) / duration. The stopping time is then calculated with: time = Vinitial / acceleration. This is reported in a formatted output as shown in the document .

The net pay on a monthly paycheck is calculated by deducting specific amounts from the gross salary. The deductions applied include 2.75% of the gross amount for Medicare/Medicaid Tax, 6% for Pension Plan, and a fixed BD. 75 for Health Insurance. The program subtracts these deductions from the gross salary to determine and print the net pay .

The area of a triangle is calculated programmatically by taking half the product of its base and height using the formula Area = 1/2 × base × height. Relevant input values required are the base and height of the triangle. This program reads these values to compute the area .

Salespeople's commission-based earnings are calculated by providing a fixed weekly base of BD. 75/600 plus 9% of their gross sales for that week. For example, if a salesperson sells BD. 1890 in chemicals, they receive the base amount plus 9% of 1890, totaling BD. 245/700. The program inputs the gross sales from each salesperson to compute their weekly earnings .

The components for calculating a student's total points include quizzes, the midterm exam, and the final exam. Quizzes are weighted at 25%, the midterm at 35%, and the final exam at 40%. The program calculates the total points by combining these weighted scores out of 100 .

The duration of a degree program in years is calculated by dividing the total program credits by the expected credits completed yearly. The expected graduation year is calculated by adding the calculated duration to the base year 2015. This program thus outputs the student's name, degree duration in years, and expected graduation year .

The program calculates average salaries by summing three input salaries and dividing by three. The output is formatted uniquely with three decimal places, enhancing precision as shown in the sample input/output (e.g., Average ...........779.157).

You might also like