Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
34 views

02.2 PB-Java-Conditional-Statements-Lab

This document provides examples of conditional statement problems for a lab exercise. It includes 7 problems of increasing complexity that involve reading user input and printing output based on conditional logic. The problems cover concepts like comparing values, checking if a number is even or odd, validating a password, and calculating geometric shapes based on user-provided dimensions. Students are instructed to code solutions in Java and test them on an online judge system.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

02.2 PB-Java-Conditional-Statements-Lab

This document provides examples of conditional statement problems for a lab exercise. It includes 7 problems of increasing complexity that involve reading user input and printing output based on conditional logic. The problems cover concepts like comparing values, checking if a number is even or odd, validating a password, and calculating geometric shapes based on user-provided dimensions. Students are instructed to code solutions in Java and test them on an online judge system.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Lab: Conditional Statements

Problems for lab exercise for the "Programming Basics" course @ SoftUni Global.
Submit your code in the Judge system: https://judge.softuni.org/Contests/Compete/Index/3449

1. Excellent Result
Write a console program that reads a rating (integer) entered by the user and prints "Excellent!" if the score is 5 or
higher.
Inpu Inpu
Input Output Output Output Input Output
t t
6 Excellent! 4 (no output) 5 Excellent! 3 (no output)

Hints and Guidelines:


1. Create a new class in the existing IntelliJ project. Right-click on the "src" folder. Select [New] 🡪 [Java Class]:

You already have a project with one class in it. It remains to write the code to solve the task.
2. Create a main method by going to the "ExcellentResult" class (between curly brackets) and type:

3. Go to the body of the main (String [] args) method (between the curly braces). Create a Scanner object to read
from the console and read a floating-point number - the grade:

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Follow us: Page PAGE \*
MERGEFORMAT 6
4. Check the value of the assessment. If it is greater than or equal to 5, print the conditional output:

5. Start the program with [Ctrl + Shift + F10] and test it with different input values:

Testing in the Judge System


Test the solution to this problem here: https://judge.softuni.org/Contests/Compete/Index/3449#0

2. Greater Number
Write a program that reads two integers entered by the user and prints the larger of the two.

Sample Input and Output


Outpu Outpu Outpu Outpu
Input Input Input Input
t t t t
5 5 3 5 10 10 -5 5
3 5 10 5

Hints and Guidelines


1. Read two integers from the console:

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Follow us: Page PAGE \*
MERGEFORMAT 6
2. Compare whether the first
number num1 is greater
than the second num2. Print
the larger number.

Testing in the Judge System


Test the solution to this problem here: https://judge.softuni.org/Contests/Compete/Index/3449#1

3. Even or Odd
Write a program that reads an integer entered by the user and prints whether it is even or odd.

Sample Input and Output


Outpu Outpu Outpu Outpu
Input Input Input Input
t t t t
2 even 3 odd 25 odd 1024 even

Hints and Guidelines


1. First, add a new Java class to the existing project.
2. Create a Scanner object and read an integer from the console:

3. Check that the number is even by dividing it by 2, and check what is the remainder of the division. Print the
output depending on the condition:

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Follow us: Page PAGE \*
MERGEFORMAT 6
Testing in the Judge System
Test the solution to this problem here: https://judge.softuni.org/Contests/Compete/Index/3449#2

4. Password Guess
Write a program that reads a password (string) entered by the user and checks if the entered password matches the
phrase "s3cr3t!P@ssw0rd". In case of coincidence, display "Welcome". In case of discrepancy, display "Wrong
password!".

Sample Input and Output


Input Output Input Output Input Output
qwerty Wrong s3cr3t!P@ssw0rd Welcome s3cr3t!p@ss Wrong
password! password!

Testing in the Judge System


Test the solution to this problem here: https://judge.softuni.org/Contests/Compete/Index/3449#3

5. Number 100...200
Write a program that reads an integer entered by the user and checks if it is below 100, between 100 and 200 or
above 200. If the number is:

● below 100 print: "Less than 100"

● between 100 and 200 print: "Between 100 and 200"

● above 200 print: "Greater than 200"

Sample Input and Output


Input Output Input Output Input Output
95 Less than 100 120 Between 100 and 200 210 Greater than 200

Testing in the Judge System


Test the solution to this problem here: https://judge.softuni.org/Contests/Compete/Index/3449#4

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Follow us: Page PAGE \*
MERGEFORMAT 6
6. Speed Info
Write a program that reads the speed (floating-point number) entered by the user and prints speed information.

● At speed up to 10 (inclusive) print "slow"

● At speed between 10 and 50 (inclusive) print "average"

● At speed between 50 and 150 (inclusive) print "fast"

● At speed between 150 and 1000 (inclusive) print "ultra fast"

● At a higher speed print "extremely fast"

Sample Input and Output


Outpu Outpu
Input Input Output Input Input Output Input Output
t t
8 slow 49.5 average 126 fast 160 ultra 3500 extremely
fast fast

Testing in the Judge System


Test the solution to this problem here: https://judge.softuni.org/Contests/Compete/Index/3449#5

7. Area of Figures
Write a program in which the user enters the type and dimensions of a geometric figure and calculates its area. The
figures are of four types: square, square, rectangle, circle, and triangle. The first line of the input reads the type of
figure (string with the following options: square, rectangle, circle, or triangle).
● If the figure is a square: on the next line read a floating-point number - the length of its side

● If the figure is a rectangle: on the next two lines read two floating-point numbers - the lengths of its sides

● If the figure is a circle: on the next line read a floating-point number - the radius of the circle

● If the figure is a triangle: on the next two lines read two floating-point numbers - the length of its side and
the length of the height to it
Round the result up to 3 digits after the decimal point.

Sample Input and Output


Input Output Input Output Input Output Input Output
square 25.000 rectangle 17.500 circle 113.097 triangle 45.00
5 7 6 4.5 0
2.5 20

Testing in the Judge System


Test the solution to this problem here: https://judge.softuni.org/Contests/Compete/Index/3449#6

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Follow us: Page PAGE \*
MERGEFORMAT 6

You might also like