Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a Java application for solving a system of two linear equations with two

ID: 3925738 • Letter: D

Question

Design a Java application for solving a system of two linear equations with two unknowns: a middotX + b middoty = c d middotX + e middoty = f where a, b, c, d, e, f are given integer numbers and x, y are unknowns (real numbers). The solutions to this system are given by the following formulas: x = (c middot e - b middot f)/(a middot e - b middot d) y = (a middot f - c middot d)/(a middot e - b middot d) Your design has to have two classes: Exl_2 and TestExl_2. The class Exl_2 should have a constructor accepting 6 parameters corresponding to the coefficients of the linear system. It has to have two public methods computex () and computeY() for computing x and y, respectively. It also has to have a method isUnique() returning true or false depending on whether a unique solution exists (i.e., the denominators of the above formulas are non-zero). The coefficients of the system should be private instance variables. The test class TestEx 1_2 must ask the user to enter 6 real numbers a, b, c, d, e, f from the keyboard, check whether a unique solution exists and if it does, output x and y. If solution is not unique (that is, if a=k middot d, b=k middot e, and c=k middot f for some non-zero k), one of solutions must be output. Otherwise, if no solution exists, the corresponding message must be printed.

Explanation / Answer

Ex1_2.java:

public class Ex1_2{
   int x,y;
   Ex1_2(int a,int b,int c,int d,int e,int f){
       x=computeX(a,b,c,d,e,f);
       y=computeY(a,b,c,d,e,f);
   }
   public int computeX(int a,int b,int c,int d,int e,int f){
       return ((c*e)-(b*f))/((a*e)-(b*d));
   }
   public int computeY(int a,int b,int c,int d,int e,int f){
       return ((a*f)-(d*c))/((a*e)-(b*d));
   }
public boolean isUnique(int a,int b,int c,int d,int e,int f){
if(a/d!=0 && b/e !=0 && c/f!=0 && d!=0 && e!=0 && f!=0)
return true;
return false;
}
   public String toString(){
   return "x coefficient = "+x+" and y coefficient = "+y;
   }
}

TestEx1_2.java:

import java.util.*;

public class TestEx1_2{
public static void main(String args[]){
int a,b,c,d,e,f;
Scanner sc = new Scanner(System.in);
System.out.println("a=");a=sc.nextInt();
System.out.println("b=");b=sc.nextInt();
System.out.println("c=");c=sc.nextInt();
System.out.println("d=");d=sc.nextInt();
System.out.println("e=");e=sc.nextInt();
System.out.println("f=");f=sc.nextInt();
Ex1_2 obj = new Ex1_2(a,b,c,d,e,f);
System.out.println(obj);
}
}