bruins301's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
6 (0.03 per day)
Joined:
15-November 12
Profile Views:
40
Last Active:
User is offline Dec 13 2012 04:50 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   bruins301 has not set their status

Posts I've Made

  1. In Topic: Gas tank program problems

    Posted 11 Dec 2012

    Thanks that question was really bugging me.
    I have another question relating to objects.
    Design a class named LinearEquation for a 2 x 2 system of linear equations.
    The class contains:
    private data fields a, b, c, d, e, f
    A constructor with the arguments a, b, c, d, e, f
    getters & setters for all private data fields
    A getX() method and getY() method that return solution for equation.
    getX() and getY() methods are always returning 0.0 no matter what I input. Here's my code
    public class LinearEquation {
    	private double a;
    	private double b;
    	private double c;
    	private double d;
    	private double e;
    	private double f;
    	private double x;
    	private double y;
    	
    	public LinearEquation(double ab, double bc, double cd, double de, double ef, double fg){
    		setA(ab);
    		setB(bc);
    		setC(cd);
    		setD(de);
    		setE(ef);
    		setF(fg);
    		
    	}
    	
    	public void setA(double first) {
    		this.a = first;
    	}
    	
    	public double getA() {
    		return this.a;
    	}
    	
    	public void setB(double second){
    		this.b = second;
    	}
    	
    	public double getB() {
    		return this.b;
    	}
    	
    	public void setC(double firstSecond){
    		this.c = firstSecond;
    	}
    	
    	public double getC() {
    		return this.c;
    	}
    	
    	public void setD(double secondSecond){
    		this.d = secondSecond;
    	}
    	
    	public double getD() {
    		return this.d;
    	}
    	
    	public void setE(double firstAnswer){
    		this.e = firstAnswer;
    	}
    	
    	public double getE() {
    		return this.e;
    	}
    	
    	public void setF(double secondAnswer){
    		this.f = secondAnswer;
    	}
    	
    	public double getF() {
    		return this.f;
    	}
    	
    	public boolean isSolvable() {
    		if((a * d) - (b * c) == 0) {
    			return false;
    		}
    		else
    			return true;
    	}
    	
    	public void setX(){
    		
    		if (isSolvable() == false){
    			System.err.println("The equation has no solution");
    		}
    		
    		else
    			x = ( (e * d) - (b * f) ) /( (a * d) - (b * c) );
    	}
    	
    	public double getX() {
    		return this.x;
    	}
    	
    	public void setY(){
    		
    		if(isSolvable() == false) {
    			System.err.println("The equation has no solution");
    		}
    		else
    			x = ( (a * f) - (e * c) ) / ((a * d) - (b * c));
    	}
    	
    	public double getY(){
    		return this.y;
    	}
    	
    	public void tester() {
    		
    		LinearEquation x = new LinearEquation(10, 10, 10, 10, 100, 100);
    		
    		System.out.println(x.getX());
    		System.out.println(x.getY());
    	}
    	
    }
    	
    
    
  2. In Topic: General Understanding of Arrays

    Posted 15 Nov 2012

    I think I found the solution to my other problem.
    numberOfIncompletes = 0;
    for(k = 0; k < incompletes.length; k++) {
    if(studentID == incompletes[k]) {
    numberOfIncompletes ++ ;
    }
    }
    
    

    The code compiled fine. I keep thinking of arrays as something different I should just look at them as a collection of variables. BTW good catch with the error in spelling I would not have caught that.
  3. In Topic: General Understanding of Arrays

    Posted 15 Nov 2012

    numberOfIncompletes = 0;
    if(studentID == incompletes[]) {
    for (k = 0; k < incompletes.length; k++) {
    numberOfIncompletes += incompletes[k];
    }
    }
    
    
  4. In Topic: General Understanding of Arrays

    Posted 15 Nov 2012

    Thank you for your input. I have another question regarding changing the values of an array. This is the question.
    Given
    *an int variable k ,
    *an int array incompletes that has been declared and initialized,
    *an int variable studentID that has been initialized, and
    *an int variable numberOfIncompletes ,
    write code that counts the number of times the value of studentID appears in incompletes and assigns this value to numberOfIncompletes .

    You may use only k , incompletes , studentID , and numberOfIncompletes .
    This is my code, but I know its off by a lot.
    numberOfIncompletes = 0;
    if(studentID == incompletes[]) {
    for (k = 0; k < incompletes.length; k++) {
    numberOfIncompletes += incompletes[k];
    }
    }
    

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

bruins301 hasn't added any friends yet.

Comments

bruins301 has no profile comments yet. Why not say hello?