Question: CPS 1 2 3 1 Lab 3 - 3 ( 2 0 points ) 1 . ( 1 0 points / 2 points each )

CPS 1231 Lab3-3(20 points)
1.(10 points /2 points each) Solve the problems below using eye. Then use Eclipse to verify your
answer.
a. Assuming that x is 1, show the result of the following Boolean expressions.
(true) && (3>4)
!(x >0) && (x >0)
(x >0)||(x <0)
(x !=0)||(x ==0)
(x >=0)||(x <0)
b. Write a Boolean expression that evaluates to true if age is greater than 13 and less than 18.
c. Write a Boolean expression for |x -5|<4.5(Hint: |x -5|<4.5 is equivalent to (x 5)>-4.5) and
(x 5)<4.5
d. Rewrite the following if statements using the conditional operator.
if (ages >=16)
ticketPrice =20;
else
ticketPrice =10;
e. Explain what the following conditional expression does.
(int)(Math.random()*2)==0?-1 : 1;
2.(10 points) Recall from lab3-2, we wrote a class, NumberToMonth, which did the following. Now,
this time, write a class called NumberToMonthUsingSwitch, that does the same but uses the switch
statement.
Ask the user to enter the month of the year (number 1 through 12): Enter the month of the
year - number 1 to 12
Get the month using a Scanner.
Checks for invalid input (i.e., numbers that are not from 1 to 12) and terminates the program
using System.exit(1) if input is invalid.
Prints the name of the month: The month is XXXXX

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!