Question
CIS 156 Java Computer Science I Lab 1 PROJECT Cylinder Geometry - Sequential Control with Java 100 points Objective To type a simple Java program,
CIS 156 |
Java Computer Science I |
Lab 1 |
PROJECT Cylinder Geometry - Sequential Control with Java 100 points
Objective To type a simple Java program, execute ( run ) the program for some particular values, observe the output and then modify the program.
PROJECT DESCRIPTION
Type, compile and run the basic Java program that is shown in Figure 1 , which follows.
Then compile and run your program, observe the output then modify the program.
Information About This Project
Programs like NetBeans and Eclipse are application development environments ( IDE ) which include text editors that you can use to write, compile and execute source code written in Java.
Business application software development often involves creating programs involving geometry. Such programs can be utilized by architects and other professionals.
This project has you create and modify a program that computes the volume and surface area of a right circular cylinder given the height of the cylinder and its base radius.
The formulas for these computations are:
Volume V of a Right Circular Cylinder
V = r 2 h ( with 3.1416 , h is the height and r is the base radius )
Surface Area S of a Right Circular Cylinder
S = 2 r h + 2 r 2 ( with 3.1416 , h is the height and r is the base radius )
The Input, Process and Output ( IPOS ) requirements of this project are:
Input the user name, the cylinder height and the cylinder base radius
Process the volume of the cylinder and the surface area of the cylinder
Output the user name, the volume of the cylinder, computed in cubic length units, and the surface area of the cylinder, computed in square length units
The course code for the volume program is given and you will modify it to include the surface area.
Steps to Complete This Project
STEP 1 Open NetBeans, Eclipse or Similar Java Development Environment
Open NetBeans, Eclipse or similar Java text editor. Here are the steps to create a Java project for this assignment using NetBeans for Windows or the Mac.
Using Eclipse
From the main menu, click [ File ] , point to [ New ] and select [ Java Project ] . When the New Java Project dialog box opens, select and fill the settings as follows:
Set the project name : Cylinder
Set the project location / project folder : ( use the default locations )
MAC users: Create Main Class : ( use the default )
Then, add a New Java Class file to the project by clicking [ File ] , pointing to [ New ] and selecting [ Class ] . With the source folder set to Cylinder\src , name the class as : Cylinder
PROJECT Cylinder Geometry - Sequential Control with Java
Into the Code window, shown below, copy in the program code shown in Figure 1 , below, in the appropriate places, except substitute your own name in place of Sammy Student.
|
Figure 1 Source Code for the Volume Program
/* Program to calculate the volume of a right circular cylinder. Programmer: Sammy Student, File Name: Cylinder.java */
// package for Scanner class objects import java.util.Scanner;
public class Cylinder { public static void main(String args[]) { // introduce a Scanner class object Scanner sc = new Scanner(System.in);
// declare and initialize the variables double height = 0, radius = 0, volume = 0; String strName = "";
// greet the program user System.out.println("Welcome to the Volume Program!"); // prompt user for their name System.out.println("please enter your name"); // read the user name strName = sc.nextLine(); //display the name back to the user System.out.println("hello " + strName);
// input: assign values to the variables System.out.print("Please enter the radius. "); radius = sc.nextDouble(); System.out.print("Please enter the height. "); height = sc.nextDouble();
// process: compute the required quantity volume = 3.1416 * radius * radius * height;
// output: display the output to the user System.out.print("The volume of the cylinder is: "); System.out.print(volume); System.out.println(" cubic length units ");
// dismiss the Scanner class object sc.close(); } }
|
PROJECT Cylinder Geometry - Sequential Control with Java
STEP 2 Build, Compile and Run the Program
From the menu select [ Run ] and click [ Run Project ( Cylinder ) ] to run your app.
If you do not have any errors, proceed to the next step, otherwise read the error messages and make any necessary corrections by comparing your screen code to
the original code shown within Figure 1 . Then run your program again.
STEP 3 Test the Program
Once you have successfully compiled your program, enter the following information, when prompted, into the output Console window of NetBeans.
Name of Program User : ( enter your own name )
The Base Radius : 2.0
The Cylinder Height : 10.0
STEP 4 Verify Your Output
When you enter the above information the Console window should show your program output, similar to the following screen snapshot.
Your program has just computed the volume of a right circular cylinder whose base radius is 2.0 and whose height is 10.0 . ( Note: the volume of a cylinder is the product of times the base radius squared times the height, where is approximated as 3.1416 )
STEP 5 Modify Your Program
Close the console output screen to return to the NetBeans Code window. Within the Code window, modify your original program code such that the program will calculate the surface area of the cylinder in addition to the volume of the cylinder.
To modify your program, first change your program comment statement to indicate that your program will also compute the surface area of the cylinder, i.e. use:
PROJECT Cylinder Geometry - Sequential Control with Java
/* Program to calculate the volume and surface area of a right circular cylinder. Programmer: Sammy Student, File Name: Cylinder.java */ |
Next, modify your variable declaration statement to include any necessary newly required variables.
double area = 0, height = 0, radius = 0, volume = 0;
Also, modify the process proportion of your program by locating the following line of code
// process: compute the required quantity
volume = 3.1416 * radius * radius * height;
and directly below the above line, assign variable area an expression that will compute the surface area of the cylinder according to the formula listed previously.
Finally, locate your output statement block, shown below.
// output: display the output to the user
System.out.print("The volume of the cylinder is: ");
System.out.print(volume);
System.out.println(" cubic length units ");
Then add in an output line directly below the output block segment above that will display the surface area of the cylinder.
STEP 6 Re - Run Your Program
Next re - run your program by repeating the steps from STEP 2 .
Test your code with data as shown below. Your output should now represent the snapshot shown below.
PROJECT Cylinder Geometry - Sequential Control with Java
STEP 7 Verify the Programs Numerical Accuracy
To verify your programs output correctness, you can open MS Excel for Windows and construct a simple worksheet, such as that given below, that will verify the output computations for your sample program run.
Your programs values may differ slightly from the above worksheet since it uses the Excel intrinsic PI() function instead of our programs 3.1416 approximation.
STEP 8 Submit Your Project
Once you have determined that your modified program is correctly computing the volume and surface area of a given right circular cylinder, complete the submission process as follows:
Open MS Word and type a heading for a new document that includes your full name, course number, lab number and date.
Within the document paste in a snapshot of your modified code. Label your snapshot with a reasonable description.
After the snapshot, paste the finished source code as copied from the Java editor.
Note - you can use the Windows Snipping Tool, which is part of the Windows Accessories Group, to easily capture your Java Console window.
Your score for each lab project will generally be based upon the following factors: documentation, output correctness, content, organization, style and creativity. Submit your Word document to the appropriate course Drop Box.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started