CSE-1020: Introduction to Computer Science I
York University
Lab Test #1: Spheres
2:30pm Monday 5 October 2009
(Lab-01)
  Welcome to the Lab-test 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.

The lab tests are closed-book and no aids are allowed.

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).

Instructions

You have the lab period, 80 minutes, to complete this lab test. The computers will automatically shutdown at the end of the time (e.g., 3:50pm), 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. Note that newer submissions overwrite older ones.

Your program will be marked for good style, as well as for running correctly (producing correct output in the correct format).

Submitting Your Work

When you submit a file, you should 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 Spheres.java before the time deadline. Here is the command to submit your work:

% submit 1020 labtest1M2.30 Spheres.java

Note that in labtest1 above, the '1' is the character one, not the letter 'L'. 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 submit it.

Useful APIs

Here are the common APIs that you may access:

Template Java Program

/* Name
 * CSE Account #
*/

import java.io.PrintStream;
import java.util.Scanner;

public class Template
{
    public static void main(String[] args)
    {
        PrintStream output = System.out;
        Scanner input = new Scanner(System.in);

    }
}
	

 
  The Task

Write a Java application called Spheres.java that solves the following problem.

You are given a positive real number Vtotal that is the total volume of liquid that needs to be stored. You are given a second positive real number Vcontainer that is the volume of one spherical container. You need to compute the number of containers needed to hold all of the liquid and the length occupied by the containers if they were placed side by side in a straight line.

Given the volume Vcontainer in metres cubed of a container, you can calculate the radius of the container using the formula:

radius = cube root of ( (3 / 4) * Vcontainer / π )

The length occupied by the containers is simply:

length = 2 * N * radius

where N is the number of containers that are needed to hold all of the liquid.

Your app should ask the user for the total volume of liquid and the volume of each container. It should output the length occupied by the containers with two decimals of precision right of the decimal point. Follow the round up half rule here (as printf does). (For example, 1.2347 would be printed as 1.235.) Your output should look exactly like that indicated in the sample runs below.

Sample Runs

Here are three sample runs of a correctly written program. Note that the text in red is text that the user types. The text in black is what the program types. The '%' represents the prompt from the command-line window (shell).

% java Spheres
Total volume of liquid (in meteres cubed): 1000.0
Volume of each container (in meters cubed): 10.0
The length of the containers is: 267.30 meters
% java Spheres
Total volume of liquid (in meteres cubed): 50.0
Volume of each container (in meters cubed): 50.0
The length of the containers is: 4.57 meters
% java Spheres
Total volume of liquid (in meteres cubed): 1.345e4
Volume of each container (in meters cubed): 150.5
The length of the containers is: 593.96 meters
%

Coding

You should use good programming practises as described in the textbook, and your code should conform to the style guide in the textbook. You should comment at least minimally, as by the guidelines.

You should not use any features of Java not covered in the first three chapters of the text; in particular, do not use if-statements or loops. There will be some deduction if you do.