03.3 - PB Java Conditional Statements Advanced Exercise
03.3 - PB Java Conditional Statements Advanced Exercise
Problems for exercise and homework for the "Programming Basics" course @ SoftUni Global.
Submit your solutions in the SoftUni Judge system at: https://judge.softuni.bg/Contests/2392
1. Cinema
In a cinema, the chairs are arranged in a rectangular shape in r rows and c columns. There are three types of
screenings with tickets at different prices:
Premiere – premiere screening, at a price of 12.00 leva (BGN).
Normal – standard screening, at a price of 7.50 leva (BGN).
Discount – screening for children, and students at a reduced to a price of 5.00 leva (BGN).
Write a program that reads the type of projection (string), a number of rows, and a number of columns in the hall
(integers) entered by the user and calculates the total ticket revenue for a full hall. Print the result in the format as
in the examples below, 2 characters after the decimal point.
3. Perform a series of checks using the ".equals()" string comparison method, assigning the appropriate price
to the "income" variable for each projection type ("Premiere, Normal, Discount") and finally printing the
final result.
2. Summer Outfit
Summer is very changing weather, and Steven needs your help. Write a program that, depending on the time of day
and the degrees, can recommend to Steven what clothes to wear. Your friend has different plans for each stage of
the day, which require a different look, you can see them on the table.
2 rows are read from the console:
© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Print on the console: "It's {degrees} degrees, get your {clothing} and {shoes}.""It's
{degrees} degrees, get your {outfit} and {shoes}."
16 It's 16 degrees, get your In the Morning when the temperature is 16,
Morning Sweatshirt and Sneakers. Steven takes a sweatshirt and sneakers.
2. Perform a series of conditions for the stage of the day, "Morning, Afternoon, Evening", and in the body of
each statement make another condition for the degrees using a logical operator "and" - "&&", as for each
range of degrees change the value of the variables "outfit and shoes" accordingly, using the table in the
problem description.
© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
3. New House
John and Nelly are buying a house not far from Sofia. Nelly loves flowers so much that she convinces you to write a
program that will calculate how much it will cost them, to plant a certain number of flowers and whether the
available budget will be enough. Different flowers have different prices.
Flowers Roses Dahlias Tulips Narcissus Gladiolus
Price in leva (BGN) 5 3.80 2.80 3 2.50
These are the following discounts:
If Nelly buys more than 80 Roses - 10% discount from the final price
If Nelly buys more than 90 Dahlias - 15% discount from the final price
If Nelly buys more than 80 Tulips - 15% discount from the final price
If Nelly buys less than 120 Narcissus - the price increases by 15%
If Nelly Buys less than 80 Gladiolus - the price increases by 20%
3 rows are read from the console:
Type of flowers - a string with options - "Roses", "Dahlias", "Tulips", "Narcissus", "Gladiolus"
Number of flowers - an integer in the range [10…1000]
Budget – an integer in the range [50…2500]
On the console print:
If the budget is enough - "Hey, you have a great garden with {number of flowers} {type of
flowers} and {remaining amount} leva left."
If the budget is not enough - "Not enough money, you need {needed money} leva more."
The amount should be formatted to the second decimal place.
Roses Not enough money, you need 25.00 Nelly wants 55 roses. The price of one rose is BGN 5,
© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Tulips Hey, you have a great garden with Narcissu Not enough money, you need
88 88 Tulips and 50.56 leva left. s 50.55 leva more.
260 119
360
4. Fishing Boat
Tony and his friends loved to go fishing. They were so passionate about fishing that they decided to go fishing by
boat. The price of renting a boat depends on the season and the number of fishermen.
The price depends on the season:
The price for renting the ship in the spring is 3000 leva (BGN).
The price for renting the ship in summer and autumn is 4200 leva (BGN).
The price for renting the ship in winter is 2600 leva (BGN).
Depending on its number, the group receives a discount:
If the group is up to 6 people inclusive - a10% discount.
If the group is from 7 to 11 people inclusive - a 15% discount
If the group is more than 12 people - a 25% discount
The fishermen receive an additional 5% discount if their group is an even number. If it is autumn - then they do not
have an additional discount.
Write a program that calculates whether fisherman will have enough money.
Input Data
3 rows are read from the console:
Group budget - an integer in the range [1…8000]
Season - string: "Spring", "Summer", "Autumn", "Winter"
Number of fishermen - an integer in the range [4…18]
Output Data
Print on the console:
If the budget is enough:
"Yes! You have {money left} leva left."
If the budget is not enough:
"Not enough money! You need {needed money} leva."
Amounts must be formatted to two decimal places after the decimal point.
3000 Not enough money! In the Summer fishing tourism costs 4200 leva (BGN), 11 fishermen enjoy a
© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
3600 Not enough money! 2000 Yes! You have 50.00 leva left.
Autumn You need 180.00 Winter
6 leva. 13
5. Journey
Strangely, most people plan their vacation early. A young programmer has an exact budget and free time for each
season. Write a program that will accept the budget and the season, and print, where the programmer will rest and
how much he will spend.
The budget determines the destination, and the season determines how much of the budget he will spend. If it is
summer, he will rest at the campsite and in the winter at a hotel. If he is in Europe, he will stay in a hotel, regardless
of the season. Each campsite or hotel, according to the destination, has its price that corresponds to a certain
percentage of the budget:
At 100 leva (BGN) or less – somewhere in Bulgaria
o Summer – 30% of the budget
o Winter – 70% of the budget
At 1000 leva (BGN) or less – somewhere in Bulgaria
o Summer – 40% of the budget
o Winter – 80% of the budget
For more than 1000 leva (BGN). – somewhere in Europe
o When traveling in Europe, regardless of the season he will spend 90% of the budget.
Input Data
2 rows are read from the console:
The budget – a floating-point number in the range [10.00...5000.00].
The season – a string "summer" or "winter"
Output Data
On the console print.
Somewhere in {destination}
{Type of holiday} – {Money spent}
o The Holiday can be a "Camp", or "Hotel"
o The amount must be rounded to the second decimal place
75 Somewhere in Bulgaria
winter Hotel - 52.50
312 Somewhere in Balkans
summer Camp - 124.80
© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Input Data
3 rows are read from the console:
N1 – an integer in the range [0...40 000]
N2 – an integer in the range [0...40 000]
Operator – symbol of: "+", "-", "*", "/", "%"
Output Data
On the console print:
If the operation is addition, subtraction, or multiplication:
o "{N1} {operator} {N2} = {result} – {even/odd}"
If the operation is a division:
o "{N1} / {N2} = {result}" – the result is formatted to the second decimal place
If the operation is division by a remainder:
o "{N1} % {N2} = {remainderr}"
In case of division by 0 (zero):
o "Cannot divide {N1} by zero"
7 7 * 3 = 21 - odd
3
*
© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Input Data
2 rows are read from the console:
On the first row the month – May, June, July, August, September, or October
On the second row is the number of nights – an integer in the range [0 ... 200]
Output Data
On the console print:
On the first line: "Apartment: {price for the whole stay} lv."
On the second line: "Studio: {price for the whole stay} lv."
The price for the entire stay must be formatted to two decimal places.
May Apartment: 877.50 lv. In May, for more than 14 nights, we reduce the price of the studio by 30%
15 Studio: 525.00 lv. (50 - 15 = 35) and the apartment - by 10% (65 - 6.5 = 58.5).
The whole stay in the apartment - 877.50 lv (BGN).
The whole stay in the studio - 525.00 lv (BGN).
Input Data
4 rows are read from the console:
The first line contains the exam time - an integer from 0 to 23.
The second line contains the minute of the exam – an integer from 0 to 59.
© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Output Data
On the first line print:
"Late" - if the student arrives later than the exam time.
"On time" - if the student arrives exactly at the time of the exam or up to 30 minutes earlier.
"Early" - if the student arrives more than 30 minutes before the exam time.
If the student arrives at least one minute apart from the exam time, print on the next line:
"mm minutes before the start" for arriving earlier by less than an hour.
"hh:mm hours before the start" or 1 hour or earlier. Always print the minutes in 2 digits, for example 1:05.
"mm minutes after the start" for an hour delay.
"hh:mm hours after the start" for a delay of 1 hour or more. Always print the minutes with 2 digits, for
example 1:03.
9. Ski Trip
John decided to spend his vacation in a ski resort. Before he leaves, however, he must book a hotel and calculate
how much his stay will cost. The following types of accommodation are available, with the following
accommodation prices:
"room for one person" – 18.00 BGN per night
"apartment" – 25.00 BGN per night
"president apartment" – 35.00 BGN per night
Depending on the number of days he will stay in the hotel (example: 11 days = 10 nights) and the type of room he
chooses, he can enjoy different discounts.
The discounts are as follows:
room type less than 10 days between 10 and 15 days more than 15 days
room for one person no discount no discount no discount
apartment 30% of the final price 35% of the final price 50% of the final price
president apartment 10% of the final price 15% of the final price 20% of the final price
© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Input Data
3 rows are read from the console:
First row - days of stay - integer in the range [0...365]
Second row – room type - "room for one person", "apartment" or "president apartment"
Third row - grade - "positive" or "negative"
Output Data
On the console print:
The price for his stay at the hotel is formatted to the second decimal place.
© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.