Jump to content


Photo
- - - - -

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


  • Please log in to reply
28 replies to this topic

#1 The Saltman

The Saltman

    I am always watching so make sure you keep your clothes on

  • Moderators
  • 24,971 posts
  • LocationAtlanta,GA

Posted 30 October 2012 - 02:18 PM

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)));
}

#2 YoungPanthers89

YoungPanthers89

    Lucy Snorebush

  • HUDDLER
  • PipPipPipPipPipPipPipPipPip
  • 11,041 posts
  • LocationNC

Posted 30 October 2012 - 02:21 PM

....7?

#3 Iceberg Slim

Iceberg Slim

    Keep it 100

  • HUDDLER
  • PipPipPipPipPipPipPipPipPip
  • 2,087 posts
  • Locationwhatcha worried about it for

Posted 30 October 2012 - 02:22 PM

Is that latin

#4 The Saltman

The Saltman

    I am always watching so make sure you keep your clothes on

  • Moderators
  • 24,971 posts
  • LocationAtlanta,GA

Posted 30 October 2012 - 02:24 PM

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

#5 leaf

leaf

    NOT NEWB

  • NEWB
  • PipPip
  • 64 posts
  • LocationHarrisburg

Posted 30 October 2012 - 02:27 PM

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.

#6 The Saltman

The Saltman

    I am always watching so make sure you keep your clothes on

  • Moderators
  • 24,971 posts
  • LocationAtlanta,GA

Posted 30 October 2012 - 02:29 PM

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.

#7 leaf

leaf

    NOT NEWB

  • NEWB
  • PipPip
  • 64 posts
  • LocationHarrisburg

Posted 30 October 2012 - 02:37 PM

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


}

#8 The Saltman

The Saltman

    I am always watching so make sure you keep your clothes on

  • Moderators
  • 24,971 posts
  • LocationAtlanta,GA

Posted 30 October 2012 - 02:41 PM

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.

#9 catfang

catfang

    Senior Member

  • ALL-PRO
  • 6,403 posts

Posted 30 October 2012 - 02:59 PM

IF

THEN

GOTO

#10 thatlookseasy

thatlookseasy

    Death to pennies

  • HUDDLER
  • PipPipPipPipPipPipPipPipPip
  • 2,950 posts

Posted 30 October 2012 - 03:09 PM

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?

#11 leaf

leaf

    NOT NEWB

  • NEWB
  • PipPip
  • 64 posts
  • LocationHarrisburg

Posted 30 October 2012 - 03:19 PM

Just make up some terms in the main method.... and then call your constructor, then call methods. Then print. then profit!!


public static void main(String[] args) {
System.out.println("The super insano calculator");
int aa =3;
int bb = 6;
.
.
int ff=8;

LinearEquation myLinearEquation = new LinearEquation(aa, bb, cc, dd, ee, ff);

int solve = myLinearEquation.isSolvable();
double x = myLinearEquation.getx();
double y = myLinearEquation.gety();

// then print .......

}

#12 Hawk

Hawk

    Huddler of the Decade

  • Moderators
  • 14,979 posts

Posted 30 October 2012 - 03:24 PM

= lamp

#13 The Saltman

The Saltman

    I am always watching so make sure you keep your clothes on

  • Moderators
  • 24,971 posts
  • LocationAtlanta,GA

Posted 30 October 2012 - 03:30 PM

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

he doesnt say .. what I posted was how he wanted the assignment. then wants me to send him the .java file.

#14 Sapper

Sapper

    Healthy Scratch

  • ALL-PRO
  • 3,000 posts
  • LocationCharlotte

Posted 30 October 2012 - 04:42 PM

Are you using Eclipse?

I don't know why they're still teaching Java.

#15 The Saltman

The Saltman

    I am always watching so make sure you keep your clothes on

  • Moderators
  • 24,971 posts
  • LocationAtlanta,GA

Posted 30 October 2012 - 04:57 PM

Yes eclipse. Java is our first language we learn.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Shop at Amazon Contact Us: info@carolinahuddle.com