public class ConditionalTestingSituationsEquality
{
public static void main(String [] args)
{
//variable declarations
boolean itIsRaining = true;
char gender = 'M';
int number = -13;
int hoursWorked = 43;
String today = "Wednesday";
int numerator = 19;
int divisor = 0;
//program logic
/*
QUESTION
"Is it raining"
OPTIONS
If it is raining, take an umbrella
Otherwise, leave the umbrella at home
*/
//As code:
if(itIsRaining == true)
{
System.out.println("It is raining. Take an umbrella");
}
else
{
System.out.println("It is not raining. Leave the umbrella at home");
}
/*
QUESTION
What gender is the applicant?
OPTIONS
If applicant selected 'M', the applicant is male
Otherwise, the applicant is female
*/
//As code:
if(gender == 'M')
{
System.out.println("The applicant is male");
}
else
{
System.out.println("The applicant is female");
}
/*
QUESTION
Is the integer positive (non-negative) or negative?
OPTIONS
If the integer is greater than -1 it is positive (non-negative)
Otherwise, the integer is negative
*/
//As code:
if(number > -1)
{
System.out.println("The integer " + number + " is positive(non-negative)");
}
else
{
System.out.println("The integer " + number + " is negative");
}
/*
QUESTION
"Does the employee get paid for overtime?"
OPTIONS
If the employee worked more than 40 hours, the employee is paid overtime
Otherwise, the employee receives regular pay
*/
//As code:
if(hoursWorked > 40)
{
System.out.println("The employee worked more than 40 hours, so " +
"the employee is to be paid overtime.");
}
else
{
System.out.println("The employee did not work more than 40 hours, so " +
"the employee is not to be paid overtime.");
}
//program logic
/*
QUESTION
What is the resulting value in the expression numerator/divisor
OPTIONS
If the divisor is zero, the program displays an error message as
division by zero is an invalid operation
Otherwise, the code displays the quotient by dividing the numerator
by the divisor
*/
//As code:
if(divisor == 0)
{
System.out.println("Invalid math operation.");
}
else
{
System.out.println(numerator/divisor);
}
/*
QUESTION
"Is today Tuesday?(The day we have Programming I class)"
OPTIONSs
"If it is Tuesday, I am excited and happy because I have class"
Otherwise, I am sad because there is no Programming I class today.
NOTE
Equality testing of strings requires the equals( ) method rather
the use of the double equals sign will not provide the
expected results
*/
if(today.equals("Tuesday"))
{
System.out.println("Hurray!!! I have Programming I class today!!!");
}
else
{
System.out.println("I am sad. I have to wait another day " +
"for Programming I class :(");
}
}
}
It is raining. Take an umbrella
The applicant is male
The integer -13 is negative
The employee worked more than 40 hours, so the employee is to be paid overtime.
Invalid math operation.
I am sad. I have to wait another day for Programming I class :(