Results 1 to 4 of 4
  1. #1
    njcountrygirl is offline Member
    Join Date
    Feb 2015
    Posts
    5
    Rep Power
    0

    Default Java Objects and Classes

    the question states: Design a class named LinearEquation
    for a 2 Χ 2 system of linear equations:
    ax + by = e
    cx + dy = f
    Where
    x =
    ed − bf/ad − bc
    y =
    af − ec/ad − bc
    The class contains:
    • Private data fields a, b, c, d, e, and f.
    • A constructor with the arguments for a, b, c, d, e, and 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 return the solution for the equation.


    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.”

    i believe that my program is correct because I am able to compile it and get no errors, however I have no clue how to display the information for x and y or display this equation has no solution if ad-bc=0.

    here is my code:
    Java Code:
    import java.util.Scanner;
    public class Exer911 {
    	public static void main(String[] args){
    		// Create a scanner system to hold the numbers for each varable 
    		Scanner input = new Scanner(System.in);
    		// Prompt the user to enter a number for each of the varables 
    		System.out.println("Enter a Number for Each of The Following Varables: a, b, c, d, e, f: ");
    		double a = input.nextDouble();
    		double b = input.nextDouble();
    		double c = input.nextDouble();
    		double d = input.nextDouble();
    		double e = input.nextDouble();
    		double f = input.nextDouble();
    
    	
    	}
    
    }
    class LinearEquation {
    	// Private data fields for a, b, c, d, e, and f  
    	private double a;
    	private double b;
    	private double c;
    	private double d;
    	private double e;
    	private double f;
    
    	// Constructor with the arguments for a, b, c, d, e, and f 
    	LinearEquation(double myA, double myB, double myC, double myD, double myE, double myF) {
                    a = myA; 
                    b = myB; 
                    c = myC; 
                    d = myD; 
                    e = myE; 
                    f = myF;
            }
    
    
    	// Method named isSolvable that returns true if ad-bc is not 0
    	boolean isSolvable() {
    		if (a*d-b*c != 0) return true;
    			else return false;
    	}
    	
    	// Method getX() that returns the solution for x in the equation 
    	double getX() {
    		double x = ((e*d)-(b*f)/(a*d-b*c));
    		return x;
    	}
    
    	// Method getY() that returns the solution for y in the equation 
    	double getY() {
    		double y = ((a*f-e*c)/(a*d-b*c));
    		return y; 
    	}
    
    	// Six getter methods for a, b, c, d, e, and f
    	
    	double getA() {
    		return a;
    	}
    
    	void setA(double newA){
    		a = newA;
    	}
    	
    	double getB(){
    		return b;
    	}
    
    	void setB(double newB){
    		b = newB;
    	}
    
    	double getC() {
    		return c;
    	}
    
    	void setC(double newC){
    		c = newC;
    	}
    	
    	double getD() {
    		return d;
    	}
    
    	void setD(double newD) {
    		d = newD;
    	}
    
    	double getE() {
    		return e;
    	}
    
    	void setE(double newE) {
    		e = newE;
    	}
    
    	double getF() {
    		return f;
    	}
    
    	void setF(double newF) {
    		f = newF;
    	}
    }

    please please please show me how to display the information i need to display before i start pulling all my hair out!

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Java Objects and Classes

    You are not creating a LinearEquation object anywhere in your code; if you had, you would be able to ask the object if it were solvable or not and print an appropiate message.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  3. #3
    njcountrygirl is offline Member
    Join Date
    Feb 2015
    Posts
    5
    Rep Power
    0

    Default Re: Java Objects and Classes

    Quote Originally Posted by JosAH View Post
    You are not creating a LinearEquation object anywhere in your code; if you had, you would be able to ask the object if it were solvable or not and print an appropiate message.

    kind regards,

    Jos
    what do you mean by this? can you please show me how?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Java Objects and Classes

    Quote Originally Posted by njcountrygirl View Post
    what do you mean by this? can you please show me how?
    For one thing, I never see something similar to this in your main( ... ) method:

    Java Code:
    LinearEquation le= new LinearEquation(a, b, c, d, e, f);
    if (le.isSolvable())
       ...
    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. New to Java. Need help writing code. (Classes and Objects)
    By AustinStanley in forum New To Java
    Replies: 6
    Last Post: 11-09-2012, 11:19 AM
  2. Objects and Classes
    By dharav in forum New To Java
    Replies: 1
    Last Post: 10-24-2012, 11:47 PM
  3. java question on classes & objects
    By joe98 in forum New To Java
    Replies: 16
    Last Post: 04-08-2011, 09:45 AM
  4. OOP Objects and Classes help
    By richlan in forum New To Java
    Replies: 5
    Last Post: 03-05-2011, 05:50 PM
  5. classes as objects
    By kroiz in forum New To Java
    Replies: 4
    Last Post: 07-25-2009, 05:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •