Attendance at the lab session on Thursday, Aug 21, is worth 20 points. It is recorded separately from the lab grade.
This is an individual lab. Every student is expected to do all the activities by themselves.
Educational goals of this lab - verify that every student can
INSTRUCTIONS:
Log onto a computer with your University userid. If you can't do this because you haven't activated your University account yet, tell your instructor. You MUST activate your University account as soon as possible!
/* * * * * * Program to find the third side of a right triangle. Author name: Class: Section: Date: Purpose: compute the hypotenuse of a right triangle, given the lengths of the two legs. Preconditions: 1. user has to input valid name 2. leg1 and leg2 have to be numbers Postconditions: Program greets you and outputs length of hypotenuse. Design: 1. ask user for name then greet the user 2. ask the user for the two legs of a right triangle and read them in 3. calculate the third side (use the Pythagorean theorem) 4. output the results with an appropriate label * * * * * */ import java.util.Scanner; class triangle { public static void main(String argv[]) { System.out.println("Hello!\nEnter your name: "); // Command to print out text Scanner user_input = new Scanner( System.in ); // user_input used for keyboard input String name = user_input.next(); // get user's name System.out.println("Hi " + name + "! We will do some math now."); // say user's name System.out.println("Enter the length of leg1: "); // ask for length of leg1 double leg1 = Float.parseFloat(user_input.next()); // get it from the keyboard and store as a double precision floatint point number System.out.println("Enter the length of leg2: "); // ask for length of leg2 double leg2 = Float.parseFloat(user_input.next()); // get it from keyboard and store it double hypotenuse = Math.sqrt(leg1*leg1 + leg2*leg2); // calculate the hypotenuse (using the Pythagorean theorem) System.out.print("The length of the hypotenuse is: "); // output/print message System.out.print(hypotenuse); // output/print the length of hypotenuse // that's it } }
Now you are going to experiment with the program given in Problem #2. In each of the cases below, make the change and run the program. If it runs alright (without errors or warnings), your answer is "runs ok". If it doesn't run alright, write down the error message that jGRASP gives, including the line number that it indicates the error or warning is on. Then change the program back to its original form before performing the next change. Use an editor like Notepad to put the answers for this problem in a file "answers-Lab1.txt". Submit this file when you are finished using the link at the bottom of the page.
When you are finished with this lab, you should have:
Submit your files with this link. Your class is CS1301, you are submitting a lab, section C, code. Use 1 menu choice from which lab or assignment
Log off properly - you don't want your account misused by someone else!
Remember NOT to leave files on the local hard drives in this lab or anywhere else on campus! Make sure you save your projects on a portable storage device you take with you!
Email sent by Thursday, August 21, midnight
Submission of triangle.java program and answers to questions due by Friday, August 22, midnight.