Solved-Lab Assignment 1 -Solution

$35.00 $24.00

PURPOSE: The purpose of this lab is to acquaint you with course Lab Policies, Procedures, and with the NetBeans the Java Software Development Environment you will use in your CS 1180/1181 courses. LAB POLICIES: Each laboratory assignment is to be worked on during your lab sessions each week. Some laboratory assignments can be completed in…

You’ll get a: . zip file solution

 

 

Description

5/5 – (2 votes)

PURPOSE: The purpose of this lab is to acquaint you with course Lab Policies, Procedures, and with the NetBeans the Java Software Development Environment you will use in your CS 1180/1181 courses.

LAB POLICIES: Each laboratory assignment is to be worked on during your lab sessions each week. Some laboratory assignments can be completed in their entirety during the scheduled lab session. Most laboratory projects will require work outside of the laboratory period during open lab hours (RC 152B) or at home. In all cases the lab must be completed and uploaded before the due date which is posted on your Pilot site. The date can be found by clicking on Dropbox in the Assessment Tab. Each lab/project assignment has its own folder. Early submission of lab/project assignments to the Pilot drop box is encouraged.

Lab assignments will generally be available in Pilot on the Sunday of the week in which the lab is assigned. This will allow time to prepare for the lab by reading the lab description and reviewing the appropriate material in the textbook before you go to the lab. You will get the most out of your laboratory time if you come to lab prepared.

For some lab assignments you must show your solution to your lab TA. The lab TA will give verbal comments regarding style, format, and correctness. If necessary, you should modify your lab submission accordingly. Only after the lab TA has reviewed your submission should you submit your lab assignment to Pilot.

If you finish a lab during the first lab session and/or have it reviewed by your TA you are not required to attend the second lab session of that week. If you are not finished after your second session you are to complete the lab at home or in an open lab and submit it before the due date/time. It is strongly suggested that in this latter case you go to the lab TA, the help room, or instructor during office hours to get verbal feedback of your lab submission. Do not wait until the last day to finish your lab or to ask for help.

Each week your lab section TA will present the laboratory assignment (including any changes/modifications to your laboratory section’s version of the assignment). This will usually include a brief review of programming concepts vital to the lab. After presenting the week’s assignment, the TA(s) will be available to (1) answer questions and provide directed help and (2) in some cases review your lab solutions

Your scheduled lab period is the only time when the TA is guaranteed to be available to review your assignments. It is your responsibility to: (1) prepare for the lab by reading the appropriate text materials, (2) attend the lab on time so that you are aware of any modifications to the lab, (3) have the TA review your lab assignment before you leave the lab, and (4) upload necessary files before the due date/time.

Late assignments: Lab assignments cannot be turned-in/graded after the following due date/time. This deadline cannot be waived by the TA. Any lab that is turned in late will receive a grade of zero. The course instructor may waive the late penalty for documented emergencies.

Final Note: Additional guidelines and expectations may be required by your TA and presented during the in-lab session. Please make note of them. If you have any questions or concerns, please do not hesitate to ask.

PROCEDURES: Your TA will walk you through the steps to bring up NetBeans. Because the lab computers do not save anything once they are restarted it will be necessary for you to save your NetBeans project when you finish. One suggestion is to put the project in a file on the desktop (or on your thumb drive). Before you turn off your computer zip the project file and either email your zipped NetBeans project to your email account or put it on a USB thumb drive or both. If you turn off the lab computer and your file was not saved from the desktop, your file cannot be recovered and you must redo the entire lab assignment.

LAB 01, PART 01: [10 pts.] Testing your understanding of the NetBeans IDE. You will create 2 projects in this lab.

Start Netbeans and create a new project. You can do this by using the File Menu and selecting New Project, by selecting the New Project Button in the icon menu bar, or using Control-Shift-N. Then create a new Java application by selecting the appropriate options in the dialogue and then selecting “Next >”.

In the next dialogue box, set the name and location of your project files. For this lab, please use the project name CS1180-Lab01-YourLastName. Set the location of this project to be the Desktop of the computer that you are using (or a folder on your own thumb drive). If you are using your own computer, create a folder where you will do the projects for this course. Then, create your new project in that folder.

Your dialog box should look something like this:

CS1180 Lab 01 Page 2

This will result in the IDE making a project with one class (CS1180La01YourLastName) containing one method (main). Netbeans will also include several comments. Your initial code created by Netbeans will look something like this.

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

License Header

* and open the template in the editor.

*/

package cs1180.lab01.doom;

/**

*

* @author Doom

*/

public class CS1180Lab01Doom {

/**

* @param args the command line arguments */

public static void main(String[] args) { // TODO code application logic here

}

}

Class Header

Method Header

The default file has three “comment sections” that begin with the characters /* and end with the characters */.

These comment sections are the license header, the class header, and the method header.

For EVERY lab or project that you turn in for a grade in this course, you will replace the License header (the part that says “ * to change this license header…) with a description of your lab (or later, project).

Put a description of your project such as ….

/**

* This is the java program for Lab 1 of CS 1180.

* This program demonstrates the use of the NetBeans IDE.

  • The program will prompt for input, do one numerical manipulation, and output results. */

Replace the default class header (after the NetBeans package statement) with the following:

/**

* your name

THIS MUST BE PRESENT ON ALL SUBMISSIONS

* your lab section number

* your lab TA’s name

* your instructor’s name

*/

For this lab, we will leave the method header alone.

Execute this initial program using “Run Project” under the Run menu (you can also run your programming using the keyboard shortcut F6 or by clicking the green arrow in the icon menu bar). It doesn’t do much right now!

CS1180 Lab 01 Page 3

ENTER AND TEST THE PROGRAM BELOW: Your TA may start this with the entire lab group. You will finish on your own from where they leave off. You may not understand all the commands of this program (yet!)

that is ok. The purpose of this first lab is to help you learn how to use Netbeans so that you can use and play with new commands as you learn them in class, in the textbook, or in lab. Note: You will NOT get much out of this assignment if you just cut and paste the entire program without taking the time to enter in each line, execute it, and observe its behavior. The instructors strongly recommend that you add each line of code to the main method one line at a time and then EXECUTE the partial program after you enter each line in order to observe the behavior of the program. This will help you build initial understanding of what each line (or set of lines) accomplishes. If your program does not execute, try to interpret the error message to determine what is wrong. Ask your TA if you can’t get the (partial) program to execute and can’t figure out why.

/*

* CS 1180 Lab 01

* This lab is just a series of steps to learn how to enter and execute

* a program in NetBeans.

*/

package cs1180.lab01.doom;

import java.util.Scanner;

import javax.swing.JOptionPane;

/**

* Travis Doom

* Lab Section: 05

* Lab TA: Timmerman

* Lecture Instructor: Doom

*/

public class CS1180Lab01Doom {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

System.out.println(“Hello world!”);

String output;

int integerNumber = 1;

System.out.print(“Integer: “);

System.out.println(integerNumber);

output = “Integer: ” + integerNumber;

System.out.println(output);

System.out.println(“Integer: ” + integerNumber);

System.out.printf(“Integer: %d”, integerNumber);

System.out.printf(“\n\n”);

double doubleNumber = 3.14; System.out.println(“Double: ” + doubleNumber); System.out.printf(“Double: %f\n”, doubleNumber); System.out.printf(“Double: %.2f\n\n”, doubleNumber);

doubleNumber = Math.PI; System.out.println(“Double: ” + doubleNumber);

CS1180 Lab 01 Page 4

System.out.printf(“Double: %f\n”, doubleNumber); output = String.format(“Double: %f\n\n”, doubleNumber); System.out.printf(output);

Scanner keyboard = new Scanner(System.in); System.out.print(“Enter any integer (e.g. -14): “); integerNumber = keyboard.nextInt();

System.out.printf(“You entered the integer %d \n”, integerNumber);

System.out.print(“Enter any decimal number (e.g. 1.23): “); doubleNumber = keyboard.nextDouble();

System.out.printf(“You entered the floating point number %.2f \n”, doubleNumber);

output = “The product of the integer and the double numbers is “; output = output + (integerNumber * doubleNumber); JOptionPane.showMessageDialog(null, output, “Lab01 Output”,

JOptionPane.INFORMATION_MESSAGE);

} // end method main

} // end class CS1180Lab01Doom

You will likely run into some problems while completing this lab. Ask the TA for help as necessary! Here are some particular things to watch out for:

  • Note the import statements between the NetBeans package statement and the class header. This are very important and easy to miss!

  • The program will eventually ask you to enter input. In order to enter input you need to CLICK in the output window and type in the value. The program will then continue.

  • If the program is waiting for input, it is running (although just waiting). You will not be able to run the program again until it either completes (after you provide the requested input) or until you stop the execution of the program. You can stop the execution of the program by clicking the small “x” by the run bar at the bottom of Netbeans, or by going to the Run Menu and selecting the option “Stop build/run” found at/near the bottom of the list of menu items.

USING THE DEBUGGER: You have entered in the entire program and are confident that it works!

Then it is time to learn how to run the program in debug mode. It is NEVER too early to learn to use the debugger! In the future, we will use the debugger to get the same “line by line” effect that you achieved in this lab by testing your program after adding each line of code.

First we will set a breakpoint. Click on the line number (left hand side) of the line of the program that prints “Hello world!”. The line should change to be shaded in red.

Click here to set/unset a breakpoint

CS1180 Lab 01 Page 5

Now run the program in debug mode. From the Debug menu, select “Debug project” (or use the Keyboard shortcut Control-F5). Note that this will bring up several tabs in Netbeans where your output window was previously. Select the “Variables” or “Output” tab to view them. Note that your program has executed to the beginning of the line where you set the breakpoint. You can also drag these windows to other parts of your NetBeans environment so that they will dock there and you can see them all simultaneously. If you move things around and can’t figure out where something disappeared to then you will want to know this VERY important option. In the “Window” menu of Netbeans there is a menu item named “Reset Windows”. This will put all the docking windows back to their “default” place.

Now use the debugger to execute your program one line at time. Watch what happens in the Output and Variables windows/tabs as you step through your program. You can step through your program one line at a time by using the Step over menu item in the Debug menu, but this quickly becomes tiresome. You will probably want to use the keyboard shortcut (F8) or the icon in the menu icon bar. Run your entire program line by line in debug mode.

The “Step Over (F8)” button is only

visible in debug mode (Control-F5)

SAVE YOUR WORK: Save your NetBeans project and close Netbeans. If you did not place the project on your thumb drive when you created the project, zip the project folder and copy it to your storage location (USB drive and/or email).

Demonstrate your program, its normal execution, its execution in the debugger and the zipped/stored project to your TA. Be prepared to answer questions from your TA about what each line of the program seems to do. DO NOT upload this part of your lab to Pilot. You WILL upload the NEXT part of the lab to Pilot.

GRADING RUBRIC for Lab 01, Part 01:

  • [2 points] Comment sections for License and Class headers contain the required information as described above

  • [3 points] The program provided above is correctly entered and its execution can be demonstrated by the student to the TA.

  • [3 points] The program is demonstrated in debug mode to the TA. Demonstrate to the TA the ability to stop the program on a particular line of the TAs choice and then answer questions regarding what will happen when the next line of the program is executed.

  • [1 points] Demonstrate for the TA how to switch between windows tabs, move/dock the output windows to a different area of the Netbeans layout AND how to return all windows to their default position using “Reset Windows”.

  • [1 points] Demonstrate to your TA that you have stored your zipped project.

CS1180 Lab 01 Page 6

SPECIAL GRADING NOTE FOR LAB 01 Part 01 ONLY: You may repeat your Lab 01, Part 01 demonstration with your TA as many times as necessary until you receive 100% credit. This first lab is supposed to develop a set of skills. Anyone not able to achieve 100% on this portion of the laboratory should speak with their instructor as soon as possible.

LAB 01, PART 02 : [10 pts.] Rectangular Prism Calculator

In this part of the lab assignment you are to construct a program on your own in NetBeans that:

  1. asks a user for the dimensions of a rectangular prism and outputs the volume and surface area.

  2. uses variables and constants with meaningful names using the accepted variable name conventions.

All of the java commands that you need to use exist in the program that you entered in the first part of this lab.

You will need to use similar commands to perform the specified task.

Create a new Netbeans project and construct a program that accomplishes the task specified above. Use the sample output below as an example of what your program should produce as output.

This program will compute the volume and surface area of a rectangular prism

Enter the prism’s length: 12.1

Enter the prism’s width: 8.7

Enter the prism’s height: 3.6

A prism with a length of 12.10 units, a width of 8.70 units, and a height of 3.60 units has a volume of 378.97 units cubed and a surface area of 360.30 units squared.

Save your Lab01 Part 02 Lab Project as a zip file. Upload your lab assignments to the Pilot drop box before YOUR lab due date/time. Ask your TA for help if you have any questions.

Demonstrate your lab assignment to your TA.

GRADING RUBRIC for Lab 01, Part 02:

  • [3 points] Program functionality matches the project description and provided sample output

  • [2 points] The program works appropriate for a wide variety of valid inputs tested by the TA

  • [1 point] Program output rounds all values to 2 decimal places using the appropriate print statement (as done in the sample output)

  • [2 points] Good use of variable names and naming conventions

  • [2 points] Comments contain the required information as described in Lab01 Part 01.

CS1180 Lab 01 Page 7