This is for JAVA Design a class named Linear Equation for a

This is for JAVA

Design a class named Linear Equation for a 2 times 2 system of linear equations: ax + by = e cx + dy = f x = ed - bf/ad - bc y = af - ec/ad - bc The class contains: Private data fields a, b, c, d, e, and f. A constructor with the arguments for a, b, c, d, e, and f. Six getter methods for a, b, c, d, e, and f. A method named is Solvable() that returns true if ad - be is not 0. Methods getX() and getY() that return the solution for the equation. Draw the UML diagram for the class and then implement the class. Write a test program that prompts the user to enter a, b, c, d, e, and f and displays the result. If ad - be is 0. report that \"The equation has no solution.\" See Programming Exercise 3.3 for sample runs.

Solution

HI, Please find my implementation.

Please let me know in case of any issue.

public class LinearEquation {

  

   // instance variables

   private int a, b, c, d, e, f;

   // constructor

   public LinearEquation(int a, int b, int c, int d, int e, int f) {

       this.a = a;

       this.b = b;

       this.c = c;

       this.d = d;

       this.e = e;

       this.f = f;

   }

   // getters

  

   public int getA() {

       return a;

   }

   public int getB() {

       return b;

   }

   public int getC() {

       return c;

   }

   public int getD() {

       return d;

   }

   public int getE() {

       return e;

   }

   public int getF() {

       return f;

   }

  

   // other functions

   public boolean isSolavable(){

       if((a*d - b*c) != 0)

           return true;

       else

           return false;

   }

  

   public double getX(){

       if(isSolavable())

           return (double)(e*d - b*f)/(double)(a*d - b*c);

       else

           return -999;

   }

  

   public double getY(){

       if(isSolavable())

           return (double)(a*f - e*c)/(double)(a*d - b*c);

       else

           return -999;

   }  

}

import java.util.Scanner;

public class LinearEquationTest {

  

   public static void main(String[] args) {

      

       Scanner sc = new Scanner(System.in);

      

       System.out.println(\"Enter value of a, b, c, d, e and f: \");

       int a = sc.nextInt();

       int b = sc.nextInt();

       int c = sc.nextInt();

       int d = sc.nextInt();

       int e = sc.nextInt();

       int f = sc.nextInt();

      

       LinearEquation eqution = new LinearEquation(a, b, c, d, e, f);

      

       System.out.println(\"isSolavable: \"+eqution.isSolavable());

       System.out.println(\"X: \"+eqution.getX());

       System.out.println(\"Y: \"+eqution.getY());

   }

}

/*

Sample run:

Enter value of a, b, c, d, e and f:

1

2

3

4

5

6

isSolavable: true

X: -4.0

Y: 4.5

*/

This is for JAVA Design a class named Linear Equation for a 2 times 2 system of linear equations: ax + by = e cx + dy = f x = ed - bf/ad - bc y = af - ec/ad - b
This is for JAVA Design a class named Linear Equation for a 2 times 2 system of linear equations: ax + by = e cx + dy = f x = ed - bf/ad - bc y = af - ec/ad - b
This is for JAVA Design a class named Linear Equation for a 2 times 2 system of linear equations: ax + by = e cx + dy = f x = ed - bf/ad - bc y = af - ec/ad - b
This is for JAVA Design a class named Linear Equation for a 2 times 2 system of linear equations: ax + by = e cx + dy = f x = ed - bf/ad - bc y = af - ec/ad - b

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site