Lab Quiz 2



Home | Resources | Homeworks | Slides | Labs | Contacts | Submit | Forums | Private

Pledged lab quiz

The only "good programming practice" that is required for this lab is to include your name and e-mail ID in the header comments. You are welcome to include more, but make sure you get the programs working first, as the quiz is timed.

The activities of this week are not to be discussed outside of lab. The quiz is open textbook but nothing else. You are to submit one program, Star.jara, which contains the Star class.  A template file is being provided.  There are to be 9 methods in Star.java, 4 of which we provide.  The Star class represents a astronomical star, to be used in a computer program.

 

Instance variables

The sample Star.java file contains four double instance variables to represent the brightness and location of the star.  The brightness of the star will be a positive number (this is not the same as astronomical magnitude).  The other three instance variables together represent the  (x, y, z) location of the star.  Our template file Star.java provides the following definitions for them.

private double brightness;
private double xLocation;
private double yLocation;
private double zLocation;

 

Methods

You are to implement five methods in the Star class.

Math.pow(e, 0.5).

The template Star.java file provides the following additional three methods -- DO NOT CHANGE THEM.

If you want to test your program you are welcomed to copy and paste into it your class. Because we will have our own testing program, it will not affect your grade whether it is included or not.

public static void main (String[] args) {

    Star s1 = new Star();
    System.out.println (s1);
    Star s2 = new Star (3, 1, 2, 3);
    System.out.println (s2);

    s1.setBrightness (5);
    s1.setLocation (0, 10);    // This should do nothing!
    s1.setLocation (1, 11);
    s1.setLocation (2, 12);
    s1.setLocation (3, 13);
    s1.setLocation (4, 14);    // This should do nothing!
    System.out.println (s1);

    double x = s2.getLocation(1);
    double y = s2.getLocation(2);
    double z = s2.getLocation(3);
    System.out.println ("s2's location is (" + x + ", " + y + ", " + z + ")");

    System.out.println ( s1.distance() );
    System.out.println ( s2.distance() );
}

Sample Output

The main() method above will produce the following output.

Star (1.0, @ (0.0, 0.0, 0.0))
Star (3.0, @ (1.0, 2.0, 3.0))
Star (5.0, @ (11.0, 12.0, 13.0))
s2's location is (1.0, 2.0, 3.0)
20.83266665599966
3.7416573867739413

Grading

Make sure each of your methods are named EXACTLY as specified.  Also, DO NOT CHANGE the other methods as they are used by the grading system.  If you do not follow these directions, the grading system will give you a zero for pretty much all of the lab quiz.

Advice

Submission

When you are finished, submit your Star.java file.