Right, so I'm two units behind, and I completly bombed the test because of it. I need to make it up to pass. I would love to understand this stuff, but I don't know if I can, because I don't understand the stuff leading up to it. So, there is a lot(20 questions), and any help would be awesome.
Straight from the test:
Code:
Public class Electron
{
public Electron(char spn, double s, double i, double j, double k)
{
spin = spn;
speed = s;
xDir = i;
yDir = j;
zDir = k;
electronCount++;
}
//notice the mass changes with speed
public static double getMass()
{
double m = restMass / Math.sqrt(1 - speed * speed / ( c * c))
return m;
}
//other methods not shown
public static final double restMass = 9.11E-31;
public static final double charge = 1.6E-19;
public static final double c - 3E8; //speed of light
public double speed;
private double xDir;
private double yDir;;
private double zDir;
private char spin;
public static int electronCount = 0;
}
1) Write a line of code that will create an Electron object called elecOne. Pass the constructor a spin value of 'u' and a speed of '2.6 X 10^6' m/sec. The direction of the electron is given by the following vector: 3i + 4j - 5k
2) Suppose you are writing code for the
main method of a
Tester class and you do not want to create and object; yet you want to find the mass (not rest mass) of an electron speeding along at 2.5 X 10^8 m/sec. Write code that will allow you to pass this speed to the class and then print the resulting mass of the electron without creating an object. Is this possible? If so, write the code. If not, state why.
3) Suppose you are creating a new class and there is a need to set the variable
e equal to
mc^2, where
m is the rest mass of an electron and
c is the speed of light. Write a line of code that does this in which you obtain
m and
c directly from the
Electron class without creating and instance of the class.
4) Suppose the following method is added to the
Electron class:
Code:
Public static double calculate(int x)
{
return xDir * x;
}
Comment on the legality of this method.
5) Suppose the following method is added to the
Electron class:
Code:
Public double calculate(int x)
{
return xDir * x;
{
Comment on the legality of this method.
7) Suppose the following code is in the
main method of a
Tester class. What is the output?
Code:
Electron elec1 = new Electron('u', 2.6E6, 3, 4, -5);
Electron elec2 = new Electron('d', 2.7E6, 3, 5, -7);
Electron elec3 = new Electron('u', 1.6E6, 3. -6. -5);
System.out.println(elec1.electronCount);
System.out.println(elec2.electronCount);
System.out.println(elec3.electronCount);
System.out.println(Electron.electronCount);