Write a class called LinearEquation that does not contain a main() method, but i
ID: 653369 • Letter: W
Question
Write a class called LinearEquation that does not contain a main() method, but it does contains the following:
Six private double fields named a, b, c, d, e, and f.
A six-argument constructor with the arguments for a, b, c, d, e, and f.
Six getter methods for a, b, c, d, e, and f.
A public boolean method named isSolvable() that returns true if ad - bc is not 0, and false otherwise.
Two public double methods named getX() and getY() that return the values of x and y respectively, using the following equations to determine the solutions:
Next, write a test program called TestLinearEquation.java that has a main()method, and that prompts the user to enter values for a, b, c, d, e, and f. Then your program will display the values of x and y, or, if ad - bc equals 0, your program should report that, "The equation has no solution."
Here is a sample input and output:
Explanation / Answer
import java.util.Scanner;
public class TestLinearEquation {
@SuppressWarnings("resource")
public static void main(String args[]) {
boolean answer = true;
String response = null;
Scanner input = new Scanner(System.in);
while (answer) {
System.out.println("Enter values for a, b, c, d, e, f: ");
double a = input.nextDouble();
double b = input.nextDouble();
double c = input.nextDouble();
double d = input.nextDouble();
double e = input.nextDouble();
double f = input.nextDouble();
LinearEquation linearEquation = new LinearEquation(a, b, c, d, e, f);
if (linearEquation.isSolvable()) {
System.out.println("The value of x is " + linearEquation.getX()
+ " and y is " + linearEquation.getY());
}else{
System.out.println("The equation has no solution");
}
System.out.print("Continue ? Press Yes");
response = input.next();
if ((response.equalsIgnoreCase("Yes")))
continue;
else
break;
}
}
}
==> TESTED
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.