Tutorial 3
Tutorial 3
Tutorial 3
Activity 1
Task
Ask the user for his age. If his age is less than 13, print the message “Not for kids”, or if it's
greater than 19, print “You’re too old”. If his age is within the range [13, 19], show message
“Welcome, teenager”.
Scanner
age < 13
13 <= age <= 19
age > 19
Expected result:
Activity 2
Leap years are years with 366 days. Write a program to check if a year is a leap year. Test your
program with different years to make sure it works correctly.
Expected result:
Activity 3
Task
Write a program to take 3 real numbers a, b and c from user and solve the quadratic equation:
ax2 + bx + c = 0
Show a message to tell the user if the equation has one, two, infinitely many roots or none, and
show the value(s) of x.
Expected result:
Please enter a: 2
Please enter b: 2
Please enter c: -4
The equation has two roots:
x1 = 1.0, x2 = -2.0
Instructions:
−b+ √ b2 −4 ac
x 1=
2a
and
−b−√ b −4 ac
2
x 2=
2a
Use Math.sqrt() to calculate the square root of a number (or expression). For instance:
double x = Math.sqrt(10); // calculate square root of 10
double dsqrt = Math.sqrt(b * b – 4 * a * c);
Submission
Submit a zip file containing all Java programs to this tutorial’s submission box in the course
website on FIT Portal.