Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java code A . In this lab you will execute the following equations based on tequation type selected by the user: a . y =
Java code A In this lab you will execute the following equations based on tequation type selected by the user:
a y mx c; This equation will be executed when eqnType ;
b y ax bx c; This equation will be executed whe h n eqnType ;
c y alogx; This equation will be executed when eqnType ;
d for any other value of eqnType print:
System.out.printlnUnsupported Equation Type!";
B Follow the steps below to complete the lab
Open the project for Lab
Add a Java file create a class name it Lab
Add a package called CSCIL
Add the Scanner library by adding the following code:
import java.util.Scanner;
import java.lang.Math;
Remember that all the library imports are added at the top of the file after the package declaration.
Add the main method if the class doesnt include one:
public static mainString args
Add codes to the main method to implement the followings with ifelse statements, logical relational, and arithmetic expressions.
a Declare an integer variable eqnType. It can have one of the following values:
i to represent linear equation
ii to represent quadratic equation
iii. to represent logarithmic equation
b Declare all needed variables as double m a b c x y Also, you must initialize them.
c Create Scanner object and add the following codes to take input from the user about the value of eqnType:
Scanner scanner new Scanner Systemin;
System.out.println
Equation Type : for Linear Equation
"Equation Type : for Quadratic Equation
"Equation Type : for Logarithmic Equations
;
System.out.printlnEnter your preferred equation type: ;
ifscannerhasNextInt
eqnType scanner.nextInt;
Create ifelse blocks to implement the following equations:
IfeqnType
statements for this block linear equation
y mx c;
else ifcondition
statements for this block quadratic equation
else ifcondition
statements for this block logarithmic equation
else
statements for this block print the message: Unsupported Equation Type!
d Print x and y using System.out.printf Make sure to use correct format specifiers.
Example: System.out.printfValuef Valuef
val val;
it prints Value Valu
e Compare the values x and y to find the larger value and print the larger number.
Example
Find larger of a and b
double largerVal;
double val;
double val;
if val val
largerVal val;
else
largerVal val;
f Evaluate the logical expression: boolean p x y && a b m; Print the result.
C Execution, Inspection, and Submission:
i Run the program.
ii Show your work to the instructor.
iii. Turn in the java file on Canvas.
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