Question: 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 = m*x + c; // This equation will be executed when eqnType =1;
b. y = a*x2+ b*x + c; // This equation will be executed whe h n eqnType =2;
c. y = a*log(x); // This equation will be executed when eqnType =3;
d. for any other value of eqnType print:
System.out.println("Unsupported Equation Type!");
B. Follow the steps below to complete the lab08.
1. Open the project for Lab08
2. Add a Java file (create a class) name it Lab08
3. Add a package called CSCI1010L
4. 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.
5. Add the main method (if the class doesnt include one):
public static main(String args[]){
}
6. Add codes to the main method to implement the followings with if-else statements, logical, relational, and arithmetic expressions.
a. Declare an integer variable eqnType. It can have one of the following values:
i.1 to represent linear equation
ii.2 to represent quadratic equation
iii. 3 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 (System.in);
System.out.println ("
Equation Type : 1 for Linear Equation
"+
"Equation Type : 2 for Quadratic Equation
"+
"Equation Type : 3 for Logarithmic Equations
");
System.out.println("Enter your preferred equation type: ");
if(scanner.hasNextInt()){
eqnType = scanner.nextInt();
}
Create if-else blocks to implement the following equations:
If(eqnType ==1){
// statements for this block linear equation
y = m*x + c;
} else if(condition2){
// statements for this block quadratic equation
} else if(condition3){
// 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.printf(Value1=%10.2f, Value2=%10.2f
, val1, val2);
it prints Value1=912.58, Valu2=52.12
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 val1=5.0,;
double val2=3.5;
if (val1> val2){
largerVal = val1;
} else {
largerVal = val2;
}
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

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 Databases Questions!