Q:

Design a class named LinearEquation for a 2 x 2 system of linear equations

0

Design a class named LinearEquation for a 2 x 2 system of linear equations:

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

class LinearEquation {
    private double a;
    private double b;
    private double c;
    private double d;
    private double e;
    private double f;

    public LinearEquation(double a, double b, double c, double d, double e, double f) {
        this.a = a;
        this.b = b;
        this.c = c;
        this.d = d;
        this.e = e;
        this.f = f;
    }

    public double getA() {
        return a;
    }

    public double getB() {
        return b;
    }

    public double getC() {
        return c;
    }

    public double getD() {
        return d;
    }

    public double getE() {
        return e;
    }

    public double getF() {
        return f;
    }

    public boolean isSolvable() {
        return (a * d - b * c) != 0;
    }

    public double getX() {
        return (e * d - b * f) / (a * d - b * c);
    }

    public double getY() {
        return (a * f - e * c) / (a * d - b * c);
    }
}

public class Main {
    public static void main(String[] args) {
        double a = 3;
        double b = 4;
        double c = 5;
        double d = 6;
        double e = 7;
        double f = 8;

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

        if (equation.isSolvable()) {
            double x = equation.getX();
            double y = equation.getY();
            System.out.println("x = " + x);
            System.out.println("y = " + y);
        } else {
            System.out.println("The equation has no solution.");
        }
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now