CSE-1020: Introduction to Computer Science I
York University
Midterm Labtest
Equations
5:00pm Wednesday 22 October 2008
(Lab-05)
  Welcome to the Labtest Environment

During the test, you will not be able to access your regular home directory, access, receive, or send e-mail, print, or access the Internet.

At the end of your test session, this machine will be converted back to a standard, unrestricted Prism Lab machine. At this time, any files written by you during the test, except those that have been submitted, will not be recoverable. Make sure you submit your code before the end of the test . (Instructions to submit your code are below). If you do not submit your work on time, you will receive a grade of zero. (There are no exceptions).

Time Limit

You have about 80 minutes to complete this test (regular lab time). The computers will automatically shutdown at the end of the lab (e.g., 6:20pm), warning you several minutes in advance. No additional time will be provided, so you must submit your work prior to this; otherwise, there will be no way to recover it (it will be lost), and you will receive a grade of zero (no exceptions).

You are encouraged to submit often during the test. Newer submissions overwrite older ones.

Submitting Your Work

When you submit a file, you must include at the top of the file your name (surname, given name) and your Prism lab login. These should be placed in a comment so that the file will compile. Note that files which do not compile will receive a large penalty when marked, no matter how small the error that prevented compiling.

Submit the class Equations.java before the time deadline. Here is the command to submit your work:

% submit 1020 midtermW5.00 Equations.java

(Further details regarding the submit command can also be obtained by typing man submit.)

Once again, you are encouraged to submit regularly. Newer submissions simply overwrite older ones.

Unlike eCheck assignments, there is partial credit possible. If you are able to finish all aspects of the program (for example, say, input validation was requested but you did not do this), you should still check it in.

Useful APIs

Here are the common APIs that you may access:

 
  The Task

Write a Java application called Equations.java. It should prompt for and then repeatedly read in three doubles: a, b and c, which will be the coefficients of the quadratic equation ax2 + bx + c = 0. For each 3 coefficients entered, use the type.lib.Equation class to solve the equation and print out one of

  • The equation <equation string> has no real roots.
  • The equation <equation string> is an identity.
  • The equation <equation string> has one real root at <root1>.
  • The equation <equation string> has two real roots at <root1> and <root2>.
where <equation string> is the string representation of the equation as returned by the toString() method of type.lib.Equation and <root1> and <root2> are the 1st and 2nd roots of the equation. After this has been done for all input equations, print out a count of each type of equation, as shown in the sample runs below.

You may assume that you are always given all 3 coefficients; i.e., you will never, for example, be given coefficient a and coefficient b but not coefficient c. You don't have to check for this; just assume it.

The input and output here are standard I/O, i.e. unless redirected, input comes from the keyboard and output goes to the screen. To signal end of file or no more input on a Unix system, just type <ctrl>d (control key and letter d at the same time) at the start of a line. (In the sample output below, the <ctrl>d typed by the user is not shown.)

The output should conform to that in the sample run of a correct program shown below. Note that, in the sample run, the % sign is not part of the program output.

Sample Runs

Here is a sample run of a correctly written program. User input is shown in red.


%
% java Equations
Repeatedly enter 3 doubles as equation coefficients.
0  0  0
The equation 0.0x^2 + 0.0x + 0.0  =  0 is an identity.
2.0  6.0  4.5
The equation 2.0x^2 + 6.0x + 4.5  =  0 has one real root at -1.500000.
9.12  1.0  2.0
The equation 9.12x^2 + 1.0x + 2.0  =  0 has no real roots.
5.0   -15.0  10
The equation 5.0x^2 - 15.0x + 10.0  =  0 has two real roots at 1.000000 and 2.000000.
5   1   1
The equation 5.0x^2 + 1.0x + 1.0  =  0 has no real roots.
1   5   1
The equation 1.0x^2 + 5.0x + 1.0  =  0 has two real roots at -4.791288 and -0.208712.
Number of equations with no real roots: 2
Number of equations with one real root: 1
Number of equations with two real roots: 2
Number of equations that are identities: 1
%
%

Coding

You should use good programming practices as described in the textbook, and your code should conform to the style guide in the textbook. Your code should be adequately commented.