Archived

This topic is now archived and is closed to further replies.

The Saltman

Any Programmers out there want to help me with a program for school?

29 posts in this topic

its in java and Im having issues getting it to print.

Here is the Question:

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

ax + by = e x = (ed – bf)/(ad – bc)

cx + dy = f y = (af – ec)/(ad – bc)

The class contains:

 Private data fields a, b, c, d, e, f.

 A constructor with the arguments for a, b, c, d, e, f.

 Six get methods for a, b, c, d, e, and f.

 A method named isSolvable() that returns true if ad – bc is not 0.

 Methods getX() and getY() that retrun the solution for the equation.

Here is what I got so far the thing is the teacher left out this part of the question on purpose so the user does not have to input anything but im still confused on how to execute the file:

Draw the UML diagram for the class. 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 – bc is 0, report that “The equation has no solution.”

so here is what I got so far. im having issues with where to put the main method and how to print it:

public class LinearEquation {

// declare the six coefficient

private static int a;

private static int b;

private static int c;

private static int d;

private static int e;

private static int f;

// a constructor to initial the coefficient

LinearEquation(int inputA, int inputB, int inputC, int inputD, int inputE, int inputF){

a = inputA;

b = inputB;

c = inputC;

d = inputD;

e = inputE;

f = inputF;

}

// method isSolvable to show whether the equations has solution or not

static int isSolvable(){

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

return 0;

else

return 1;

}

// method getX() to calculate the solution of x

static double getX(){

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

}

// method getY() to calculate the solution of y

static double getY(){

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

}

Share this post


Link to post
Share on other sites

lol. this is my intro to programming class. My teacher is a horrible teacher and if it isnt perfect I get a 0

So any help would be appreciated

Share this post


Link to post
Share on other sites

Don't you just need 1 more method (public static void main ) that will prompt the user for the 6 variables and then call the methods, and print out the result ?

main can go anywhere. Top, middle bottom. I like it on the bottom, with my constructors on top.

Share this post


Link to post
Share on other sites

well my idiotic teacher never asked for the user to input anything,

He basically cut out a part of the original problem from the book

thats where im having the problem.

Share this post


Link to post
Share on other sites

Use the Scanner class to get input....

public static void main(String[] args) {

System.out.println("The super insano calculator");

Scanner reader = new Scanner(System.in);

System.out.println("Enter the first number");

//get user input for a

int a=reader.nextInt();

// yadda yadda

//repeat for other variables and then call your contructor.

// Then call your methods

// then print

}

Share this post


Link to post
Share on other sites

but like I said before my teacher doesnt want the user to input anything. Im assuming that means not to use the scanner class? like I said my teacher sucks.

Share this post


Link to post
Share on other sites

but like I said before my teacher doesnt want the user to input anything. Im assuming that means not to use the scanner class? like I said my teacher sucks.

Then just call your function in your main method with whatever input you feel like. How does he want you to submit this assignment?

Share this post


Link to post
Share on other sites



  • Topics

  • Posts

    • Yep, value is based on all the mocks people read. Bradberry was a horrible pick after the draft because he wasn't good value. Well, he played as well as most of the 1st round CBs and better than all of the 2nd rounders picked before him.
    • When I played sports and coached I've been in the same position as Ron. If the player tells you he is good you let him play. It shows you trust him. Everyone is banged up in the NFL and it's the medical and the player who have to make the call to shut it down. 
    • 1) Browns - DE Garrett - They cannot possibly fug this up 2) 49ers - DE Solomon Thomas - SF goes for best available player and Thomas stays in the Bay area. Would give them a tremendous front line w/Armstead and Buckner. 3) Bears - SS Adams - Fills a major need for them. They haven't had a quality safety since Mike Brown 4) JAX - RB Leonard Fournette - Jags are trying really, really hard to be relevant. From those ridiculous uniforms to the stupid pool in that stadium. Yes, they already have 2 RB's but neither is very good. Fournette will sell tickets. 5) Titans - CB Marshon Lattimore - Titans go for best CB on the board. Could also go for safety Malik Hooker. 6) Jets - TE OJ Howard - These are the current TE's on Jets roster: 84 Braedon Bowman 88 Austin Seferian-Jenkins 83 Eric Tomlinson 85 Jason Vander Laan 7) Chragers - DE Jonathan Allen - Chargers run a 3-4 defense and Allen would fit in perfectly. LA could also go with Malik Hooker here.            - This mock would be the worst possible scenario for us - And you can see that there would still be good players (Hooker, Allen, Barnett) available for us. We're fine.