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

Hi im doing this project for class and i cant get it to work. this is for my jav

ID: 3625661 • Letter: H

Question

Hi im doing this project for class and i cant get it to work. this is for my java class. i was given a equation.java file that had these codes in it
* <p>CS110 Project 3 test cases</p> */?import junit.framework.TestCase;?public class EquationTest extends TestCase{ // test cases for a single equation object    public void testSingleEquation() { Equation uut = new Equation( 1, 1, 1); assertEquals(-1.0, uut.slope(), Equation.THRESHHOLD); assertEquals( 1.0, uut.intercept(), Equation.THRESHHOLD); assertEquals("1x +1y = 1", uut.toString());     uut = new Equation( 1, -1, 4); assertEquals( 1.0, uut.slope(), Equation.THRESHHOLD); assertEquals(-4.0, uut.intercept(), Equation.THRESHHOLD); assertEquals("1x -1y = 4", uut.toString());     uut = new Equation(-1, 2, -1); assertEquals( 0.5, uut.slope(), Equation.THRESHHOLD); assertEquals(-0.5, uut.intercept(), Equation.THRESHHOLD); assertEquals("-1x +2y = -1", uut.toString());     try { uut = new Equation(1, 0, 1); assertEquals(0.0, uut.slope(), Equation.THRESHHOLD); // exception should occur assertTrue(false); // should not execute this } catch (ArithmeticException e) { // exception is expected assertTrue(e.toString().contains("Infinite Slope")); }     try { uut = new Equation(1, 0, 1); assertEquals(0.0, uut.intercept(), Equation.THRESHHOLD); // exception should occur assertTrue(false); // should not execute this } catch (ArithmeticException e) { // exception is expected assertTrue(e.toString().contains("No Unique Intercept")); } }    // test cases for solving pairs of equations for x and y    public void testSolvingPairs() { try { Equation uut1 = new Equation(1, 1, 4); Equation uut2 = new Equation(1, -1, 2); assertEquals(3.0, uut1.solveForXWith(uut2), Equation.THRESHHOLD); assertEquals(1.0, uut1.solveForYWith(uut2), Equation.THRESHHOLD); assertEquals(3.0, uut2.solveForXWith(uut1), Equation.THRESHHOLD); assertEquals(1.0, uut2.solveForYWith(uut1), Equation.THRESHHOLD); assertTrue(uut1.verifySolution(3.0, 1.0)); assertTrue(uut2.verifySolution(3.0, 1.0)); } catch (ArithmeticException e) { // no exception expected assertTrue(false); // should not execute this }     try { Equation uut1 = new Equation(1, 1, 1); Equation uut2 = new Equation(2, 2, 2); assertEquals(0.0, uut1.solveForXWith(uut2), Equation.THRESHHOLD); assertTrue(false); // should not execute this } catch (ArithmeticException e) { // exception is expected assertTrue(e.toString().contains("Parallel Lines")); }     try { Equation uut1 = new Equation(1, 1, 1); Equation uut2 = new Equation(1, 1, 3); assertEquals(0.0, uut1.solveForYWith(uut2), Equation.THRESHHOLD); assertTrue(false); // should not execute this } catch (ArithmeticException e) { // exception is expected assertTrue(e.toString().contains("Inconsistent Equations")); } }    // test cases for implementing interface Comparable    public void testComparability() { Comparable<Equation> uut1 = new Equation(1, 1, 1); Equation uut2 = new Equation(-1, 1, 1); assertEquals(-1, uut1.compareTo(uut2)); assertEquals( 0, uut2.compareTo(uut2)); assertEquals(+1, uut2.compareTo( (Equation) uut1)); // cast uut1 back to what it was born as }
and i have to write some codes that:
Code outside of your Equation class can do the following:



1. Create Equation objects by calling the Equation constructor with three coefficients as arguments, for example:



     // create an Equation object to represent: 2x + 3y = 6

     Equation myEquation = new Equation(2, 3, 6);



2. Display Equation objects using the toString method, for example:



            // print an Equation

     System.out.println(myEquation.toString());



3. Get the slope or y-axis intercept for the equation, for example:



            // print the slope and intercept for an Equation

     System.out.println(myEquation.slope());

System.out.println(myEquation.intercept());



4. Compare Equation objects using the compareTo method, for example:



            // compare two equations

     if(myEquation.compareTo(yourEquation) < 0)

          valid Java statement for when mine is less than yours;



5. Solve a pair of Equations and verify the solution, for example:



            // solve a pair of Equations for X (or Y)

     double x = myEquation.solveForXWith(yourEquation);



Notice that after code outside of the Equation class creates an Equation object with a given set of coefficients, it does not ever need to access the coefficient values again.  So there is no need foraccessor or “getter” methods to get the values of individual coefficients. All operations using the coefficients of Equation objects are done in the code of the Equation class methods, for example:



            // part of compareTo - compare the slopes of two objects

     double difference = this.slope() – that.slope();


all the information is given on this web site : http://www.cs.umb.edu/~bobw/CS110/Project3/index.html
PLEASE HELP I CANT GET IT TO WORK RIGHT!!

Explanation / Answer

You have to create an Equation class yourself and this test class only checks it. Also, you need to add Junit 4 to build path. If you are using eclipse, just right click on the project, on Build Path menu, select add Libraries and then select Junit and then Junit 4. Attached below is the equation: I would suggest you also try on your own now that you understand what to do. Also you need to implement another class with a main method and using the equation class. ______________________________________________________________________________ package test; public class Equation implements Comparable { public static final double THRESHHOLD = 0.001; private int x,y,z; private Double slope = null; public Equation(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public double slope() { if(slope == null) { getSlope(); } return slope; } private void getSlope() throws ArithmeticException { if(this.y == 0) { throw new ArithmeticException("Infinite Slope"); } slope = (-((double)this.x/(double)this.y)); } public double intercept() { if(this.y == 0) { throw new ArithmeticException("No Unique Intercept"); } return ((double)this.z/(double)this.y); } public double solveDenominator(Equation eq) { return ((this.x*eq.y)-(eq.x*this.y)); } public double solveForXWith(Equation eq) { double denominator = solveDenominator(eq); double numerator = ((this.z*eq.y)-(eq.z*this.y)); checkForZeros(denominator, numerator); return numerator / denominator; } public double solveForYWith(Equation eq) { double denominator = solveDenominator(eq); double numerator = ((this.x*eq.z)-(eq.x*this.z)); checkForZeros(denominator, numerator); return numerator / denominator; } private void checkForZeros(double denominator, double numerator) { if(denominator == 0 && numerator == 0) { throw new ArithmeticException("Parallel Lines"); } else if(denominator == 0) { throw new ArithmeticException("Inconsistent Equations"); } } public boolean verifySolution(double a, double b) { return( ((this.x * a) + (this.y * b)) == this.z); } @Override public int compareTo(Equation eq) { double difference = this.slope() - eq.slope(); if(difference < 0) difference = (-1) * difference; if(difference eq.slope()) { return 1; } else { return -1; } } @Override public String toString() { if(this.y >= 0) { return this.x+"x +" + this.y+"y = "+this.z; } else { return this.x+"x -" + (this.y*(-1))+"y = "+this.z; } } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote