Equation2 - else { if (a != 0) { if (a==-1)...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // Equation2.java Authors: Lewis and Loftus // // Solution to Programming Project 9.9 // // Encapsulates the equation used in EquationFrame.java and // ViewportPanel.java // // Represents the equation a*x^2 + b*x + c //******************************************************************** / public class Equation2 { int a; int b; int c; final String SQUARED = "\u00B2"; public Equation2() { a = b = c = 0; } public Equation2(int aValue, int bValue, int cValue) { a = aValue; b = bValue; c = cValue; } public float computeValue(float x) { return a*x*x + b*x + c; } public String toString() { StringBuffer equation = new StringBuffer(); equation.append("0");
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: else { if (a != 0) { if (a==-1) equation.append("-"); else if (a!=1) equation.append(a); equation.append( "x" + SQUARED); } if (b != 0) { if (b < 0) { if (a==0) equation.append("-"); else equation.append(" - "); b = -b; } else equation.append(" + "); if (b!=1 && b!= -1) equation.append(b); equation.append("x"); } if (c != 0) { if (c < 0) { if (a!=0 || b!=0) equation.append(" - "); else equation.append("-"); c = -c; } else equation.append(" + "); equation.append(c); } } // erase leading + if (equation.length() > 2) { char ch = equation.charAt(1); if (ch=='+') { equation.deleteCharAt(0); equation.deleteCharAt(0); } } return equation.toString(); } }...
View Full Document

This note was uploaded on 05/17/2011 for the course COP 3530 taught by Professor Davis during the Spring '08 term at University of Florida.

Page1 / 2

Equation2 - else { if (a != 0) { if (a==-1)...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online