CS10, 09S, UCSB
H10: (Based on Horstman, Chapters 7, 8) Total points: ? (printable PDF)
Accepted: on paper, in lecture (1-1:50pm) on Wednesday, May 6th only.
No email submission allowed.
Name: (2 pts)______________________________ UCSBNetID (2 pts) _____________________
Section (6 pts) Circle one: Thu 4pm Fri 10am Fri 11am Fri noon
public Complex (double real, double imag);and these method (only):
double getReal();Then, suppose we have a QuadraticEqn class that has this constructor:
double getImag();
public QuadraticEqn(double a, double b, double c);and these methods:
public void setA(double a);
public void setB(double b);
public void setC(double c);
public double getA();
public double getB();
public double getC();
public int numRealRoots();
public double realRoot1(); // result of applying + from quadratic formula
public double realRoot2(); // result of applying - from quadratic formula
public Complex complexRoot1(); // result of applying + from quadratic formula
public Complex complexRoot2(); // result of applying - from quadratic formula
Complex "depend on" Quadratic? yes noQuadraticEqn "depend on" Complex? yes noPlease turn over for more problems
public class WhatIsTheOutput1
{
public void setToZero(int x)
{
x = 0;
}
public void tryIt()
{
int y=3;
setToZero(y);
System.out.println("y=" + y);
}
/**
* main method
*
* @param args arguments to main method (ignored in this case)
*/
public static void main (String [] args)
{
WhatIsTheOutput1 wito = new WhatIsTheOutput1();
wito.tryIt();
}
}
public class WhatIsTheOutput2
{
public void setToZero(Integer x)
{
x = 0;
}
public void tryIt()
{
Integer y=3;
setToZero(y);
System.out.println("y=" + y);
}
public static void main (String [] args)
{
WhatIsTheOutput2 wito = new WhatIsTheOutput2();
wito.tryIt();
}
}