java eduwitcscomp1050PA3b Please supply 6 numbers af java

$ java edu.wit.cs.comp1050.PA3b

Please supply 6 numbers (a-f).

$ java edu.wit.cs.comp1050.PA3b 1.0 2.0 2.0 4.0 4.0 5.0

The equation has no solution.

$ java edu.wit.cs.comp1050.PA3b 9.0 4.0 3.0 -5.0 -6.0 -21.0

Solution: x=-2.000, y=3.000

Here is my code in the Linear Equation class.

public class LinearEquation {

private double a;

private double b;

private double c;

private double d;

private double e;

private double f;

   /**

   * Initialize the linear equation of form:

   * ax + by = e

   * cx + dy = f

   *

   * @param a parameter a

   * @param b parameter b

   * @param c parameter c

   * @param d parameter d

   * @param e parameter e

   * @param f parameter f

   */

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

       // replace with your code

this.a = a;

this.b = b;

this.c = c;

this.d = d;

this.e = e;

this.f = f;

   }

  

   /**

   * Convenience constructor to initialize

   * the linear equation via array

   *

   * THIS CONSTRUCTOR CALLS THE CONSTRUCTOR

   * ABOVE USING THE ARRAY CONTENTS

   *

   * @param p parameter array, assumed to be length 6 (a-f, in order)

   */

   public LinearEquation(double[] p) {

       // MUST call the above constructor

       // with the contents of p

   }

  

   /**

   * Returns parameter a

   *

   * @return a

   */

   public double getA() {

       return a; // replace with your code

   }

  

   /**

   * Returns parameter b

   *

   * @return b

   */

   public double getB() {

       return b; // replace with your code

   }

  

   /**

   * Returns parameter c

   *

   * @return c

   */

   public double getC() {

       return c; // replace with your code

   }

  

   /**

   * Returns parameter d

   *

   * @return d

   */

   public double getD() {

       return d; // replace with your code

   }

  

   /**

   * Returns parameter e

   *

   * @return e

   */

   public double getE() {

       return e; // replace with your code

   }

  

   /**

   * Returns parameter f

   *

   * @return f

   */

   public double getF() {

       return f; // replace with your code

   }

  

   /**

   * Returns true if the parameterized

   * equation is solvable (i.e. denominator

   * ad-bc is not 0)

   *

   * @return true if solvable, false otherwise

   */

   public boolean isSolvable() {

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

           return false;

       else

           return true; // replace with your code

   }

  

   /**

   * Returns solution for x if solvable,

   * null otherwise

   *

   * @return x if solvable, null otherwise

   */

   public Double getX() {

       double numerator = ((e * d)-(b * f));

       double denominator = ((a * d) - (b * c));

       return numerator/denominator;

   }

  

   /**

   * Returns solution for y if solvable,

   * null otherwise

   *

   * @return y if solvable, null otherwise

   */

   public Double getY() {

       double numerator = ((a * f)-(e * c));

       double denominator = ((a * d) - (b * c));

       return numerator/denominator;

   }

}

Here is Main class with some code ?

public class PA3b {

  

   /**

   * Error to display if the command-line arguments are invalid

   */

   public static final String ERR_USAGE = \"Please supply 6 numbers (a-f).\";

  

   /**

   * Error to display if the equation has no solution

   */

   public static final String ERR_NOSLTN = \"The equation has no solution.\";

  

   /**

   * Number of required parameters (a-f)

   */

   public static final int NUM_PARAMS = 6;

  

   /**

   * Validates command-line arguments and returns

   * parameters if valid

   *

   * @param args command-line arguments

   * @return if valid an array of parameters, else null

   */

   public static double[] validateArgs(String[] args) {

       if(args.length > 5){

       }

       return null; // replace with your code

   }

   /**

   * Uses command-line arguments to create

   * an instance of the linear equation,

   * and reports the outcome

   *

   * @param args command-line arguments, interpreted as equation parameters

   */

   public static void main(String[] args) {

   }

}

ar by e

Solution

// LinearEquation.java

/*
* Class to solve linear equation
* ax + by = e
* cx + dy = f
*/
public class LinearEquation {


   private double a;
private double b;
private double c;
private double d;
private double e;
private double f;
  
   /**
   * Initialize the linear equation of form:
   * ax + by = e
   * cx + dy = f
   *
   * @param a parameter a
   * @param b parameter b
   * @param c parameter c
   * @param d parameter d
   * @param e parameter e
   * @param f parameter 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;
   }

/**
* Convenience constructor to initialize
* the linear equation via array
*
* THIS CONSTRUCTOR CALLS THE CONSTRUCTOR
* ABOVE USING THE ARRAY CONTENTS
*
* @param p parameter array, assumed to be length 6 (a-f, in order)
*/
public LinearEquation(double[] p) {
   this(p[0], p[1], p[2], p[3], p[4], p[5]);
}
  

/**
* Returns parameter a
*
* @return a
*/
public double getA() {
return a; // replace with your code
}
  
/**
* Returns parameter b
*
* @return b
*/
public double getB() {
return b; // replace with your code
}
  
/**
* Returns parameter c
*
* @return c
*/
public double getC() {
return c; // replace with your code
}
  
/**
* Returns parameter d
*
* @return d
*/
public double getD() {
return d; // replace with your code
}
  
/**
* Returns parameter e
*
* @return e
*/
public double getE() {
return e; // replace with your code
}
  
/**
* Returns parameter f
*
* @return f
*/
public double getF() {
return f; // replace with your code
}


   /**
   * Returns true if the parameterized
   * equation is solvable (i.e. denominator
   * ad-bc is not 0)
   *
   * @return true if solvable, false otherwise
   */
   public boolean isSolvable() {
   if (((a*d) -(b*c)) == 0 )
   return false;
   else
   return true; // replace with your code
   }
  
/**
* Returns solution for x if solvable,
* null otherwise
*
* @return x if solvable, null otherwise
*/
   public Double getX()
   {
       Double solution = null;
       if (isSolvable())
           solution = (double)(e*d - b*f)/(a*d - b*c);
      
       return solution;
   }

   /**
   * Returns solution for y if solvable,
   * null otherwise
   *
   * @return y if solvable, null otherwise
    */
   public Double getY()
   {
       Double solution = null;
       if (isSolvable())
           solution = (double)(a*f- e*c)/(a*d - b*c);
      
       return solution;
   }

}

// PA3b.java

import java.text.DecimalFormat;
import java.util.Scanner;

public class PA3b {
  
   /**
   * Error to display if the command-line arguments are invalid
   */
   public static final String ERR_USAGE = \"Please supply 6 numbers (a-f).\";
  
   /**
   * Error to display if the equation has no solution
   */
   public static final String ERR_NOSLTN = \"The equation has no solution.\";
  
   /**
   * Number of required parameters (a-f)
   */
   public static final int NUM_PARAMS = 6;
  
   /**
   * Validates command-line arguments and returns
   * parameters if valid
   *
   * @param args command-line arguments
   * @return if valid an array of parameters, else null
   */
   public static double[] validateArgs(String[] args) {
       double[] p = new double[NUM_PARAMS];
   if(args.length == NUM_PARAMS){
       for (int i = 0; i < args.length; i++)
       {
           try{
               p[i] = Double.parseDouble(args[i]);
           }
           catch(Exception e)
           {
               System.out.println(\"Seems like inputs are not numbers\");
               System.exit(1);
           }
       }
   }
   else
   {
       System.out.println(ERR_USAGE);
       System.exit(1);
   }
   return p; // replace with your code
   }
   /**
   * Uses command-line arguments to create
   * an instance of the linear equation,
   * and reports the outcome
   *
   * @param args command-line arguments, interpreted as equation parameters
   */
   public static void main(String[] args) {
       double[] p = validateArgs(args);
       LinearEquation l = new LinearEquation(p);
         
       if (! l.isSolvable())
       {
           System.out.println(ERR_NOSLTN);
       }
       else
       {
           DecimalFormat df = new DecimalFormat(\"##.000\");
           System.out.println(\"Solution: x=\" + df.format(l.getX())
                   + \",y=\" + df.format(l.getY()));
       }
         
         
   }
}

$ java edu.wit.cs.comp1050.PA3b Please supply 6 numbers (a-f). $ java edu.wit.cs.comp1050.PA3b 1.0 2.0 2.0 4.0 4.0 5.0 The equation has no solution. $ java edu.
$ java edu.wit.cs.comp1050.PA3b Please supply 6 numbers (a-f). $ java edu.wit.cs.comp1050.PA3b 1.0 2.0 2.0 4.0 4.0 5.0 The equation has no solution. $ java edu.
$ java edu.wit.cs.comp1050.PA3b Please supply 6 numbers (a-f). $ java edu.wit.cs.comp1050.PA3b 1.0 2.0 2.0 4.0 4.0 5.0 The equation has no solution. $ java edu.
$ java edu.wit.cs.comp1050.PA3b Please supply 6 numbers (a-f). $ java edu.wit.cs.comp1050.PA3b 1.0 2.0 2.0 4.0 4.0 5.0 The equation has no solution. $ java edu.
$ java edu.wit.cs.comp1050.PA3b Please supply 6 numbers (a-f). $ java edu.wit.cs.comp1050.PA3b 1.0 2.0 2.0 4.0 4.0 5.0 The equation has no solution. $ java edu.
$ java edu.wit.cs.comp1050.PA3b Please supply 6 numbers (a-f). $ java edu.wit.cs.comp1050.PA3b 1.0 2.0 2.0 4.0 4.0 5.0 The equation has no solution. $ java edu.
$ java edu.wit.cs.comp1050.PA3b Please supply 6 numbers (a-f). $ java edu.wit.cs.comp1050.PA3b 1.0 2.0 2.0 4.0 4.0 5.0 The equation has no solution. $ java edu.
$ java edu.wit.cs.comp1050.PA3b Please supply 6 numbers (a-f). $ java edu.wit.cs.comp1050.PA3b 1.0 2.0 2.0 4.0 4.0 5.0 The equation has no solution. $ java edu.
$ java edu.wit.cs.comp1050.PA3b Please supply 6 numbers (a-f). $ java edu.wit.cs.comp1050.PA3b 1.0 2.0 2.0 4.0 4.0 5.0 The equation has no solution. $ java edu.
$ java edu.wit.cs.comp1050.PA3b Please supply 6 numbers (a-f). $ java edu.wit.cs.comp1050.PA3b 1.0 2.0 2.0 4.0 4.0 5.0 The equation has no solution. $ java edu.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site