Answered step by step
Verified Expert Solution
Link Copied!

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 = 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

60 Workplace safety risks.

Answered: 1 week ago

Question

Define organisational structure

Answered: 1 week ago

Question

Define line and staff authority

Answered: 1 week ago

Question

Define the process of communication

Answered: 1 week ago

Question

Explain the importance of effective communication

Answered: 1 week ago

Question

* What is the importance of soil testing in civil engineering?

Answered: 1 week ago

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago