Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Follow the steps below to complete the lab 0 9 . Open the project for Lab 0 9 Add a Java file ( create a
Follow the steps below to complete the lab
Open the project for Lab
Add a Java file create a class name it Lab
import java.lang.Math;
Add the main method:
public static mainString args
Reference codes:
a Equivalent Switch statements and ifelse statement are shown below:
switchoperator
case :
result ;
break;
case :
result ;
break;
case :
result ;
break;
case :
result ;
break;
default:
System.out.print In Invalid operator";
break;
lelse this is equivalent to 'default' in the switch statement
System.out.printIn "Invalid operator";
b Conditional Operator:
int maxval, x x;
maxval x x x : x;
The above implementation with Conditional Operator is equivalent to this is also the algorithm to find the larger between two numbers:
ifx x
maxval x;
else
maxval x;
Add codes to the main method to implement the followings with switch statements, logical relational, and arithmetic expressions.
aWrite the name of the course in a single line comment
b
Write the course description in a multiline comment
c Print the values of the following variables:
int x ; double y ; float z f; String course CSCIL;
i Using println method
ii Using printf method. Make sure to add new line escape character at the end of the format specifier.
d Find and print the lower number between the following variables:
int var; int var;
e Convert the following ifelse statements into switch statements:
ifeqnType
y mx c;
else ifeqnType
y aMathpowx bx c;
else if eqnType
y aMathlogx;
else
System.out.printlnUnsupported Equation Type";
Make sure to declare eqnType as int type and all other needed variables as double m a b c x y Also, you must initialize them except y
f Use conditional operator to compare the values a and b and to find the larger value and print the larger number.
g Compare values x and y with digits of precision and implement the following logic with Condition Operator.
final double TOLERANCE ;
String msg ;
String msg "Absolute difference between x & y is less than the Tolerance";
String msg "Absolute difference between x & y is not less than the Tolerance";
if Mathabsx y TOLERANCE
msg msg;
else
msg msg;
System.out.printlnmsg;
hBonus
Use Conditional Operator to Compare the values a b and c to find out the largest number. Print the largest number.
Following codes implement the problem with if block.
Find the largest of a b c
double largest a;
if b largest
x b;
if c largest
x c;
Run the program
java
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started